Beispiel #1
0
def test_model_joblib():
    sklearn_model, data = _train_sample_model()
    model_file = os.path.join(JOBLIB_FILE[0], JOBLIB_FILE[1])
    joblib.dump(value=sklearn_model, filename=model_file)
    model = SKLearnModel("model", JOBLIB_FILE[0])
    model.load()
    request = data[0:1].tolist()
    response = model.predict({"instances": request})
    assert response["predictions"] == [0]
Beispiel #2
0
def _run_pickle_model(model_dir, model_name):
    sklearn_model, data = _train_sample_model()
    model_file = os.path.join(model_dir, model_name)
    pickle.dump(sklearn_model, open(model_file, 'wb'))
    model = SKLearnModel("model", model_dir)
    model.load()
    request = data[0:1].tolist()
    response = model.predict({"instances": request})
    assert response["predictions"] == [0]
Beispiel #3
0
def test_model():
    iris = datasets.load_iris()
    X, y = iris.data, iris.target
    sklearn_model = svm.SVC(gamma='scale')
    sklearn_model.fit(X, y)
    model_file = os.path.join((model_dir), JOBLIB_FILE)
    joblib.dump(value=sklearn_model, filename=model_file)
    server = SKLearnModel("sklearnmodel", model_dir)
    server.load()
    request = X[0:1].tolist()
    response = server.predict(request)
    assert response == [0]
Beispiel #4
0
def test_mixedtype_model_joblib():
    model = SKLearnModel("model", MIXEDTYPE_DIR)
    model.load()
    request = [{
        'MSZoning': 'RL',
        'LotArea': 8450,
        'LotShape': 'Reg',
        'Utilities': 'AllPub',
        'YrSold': 2008,
        'Neighborhood': 'CollgCr',
        'OverallQual': 7,
        'YearBuilt': 2003,
        'SaleType': 'WD',
        'GarageArea': 548
    }]
    response = model.predict({"instances": request})
    assert response["predictions"] == [12.202832815138274]