Ejemplo n.º 1
0
def test_regressor_mg_train_sg_predict(datatype, keys, data_size,
                                       fit_intercept, client):

    nrows, ncols, n_info = data_size
    X_train, y_train, X_test = make_dataset(datatype, nrows, ncols, n_info)

    X_test_local = X_test.compute()

    dist_model = LinearRegression(fit_intercept=fit_intercept, client=client)
    dist_model.fit(X_train, y_train)

    expected = dist_model.predict(X_test).compute()

    local_model = dist_model.get_combined_model()
    actual = local_model.predict(X_test_local)

    assert_equal(expected.get(), actual.get())
Ejemplo n.º 2
0
def test_get_combined_model(datatype, keys, data_size, fit_intercept, client):

    nrows, ncols, n_info = data_size
    X_train, y_train, X_test = make_dataset(datatype, nrows, ncols, n_info)
    model = LinearRegression(fit_intercept=fit_intercept, client=client)
    model.fit(X_train, y_train)

    combined_model = model.get_combined_model()
    assert combined_model.coef_ is not None
    assert combined_model.intercept_ is not None

    y_hat = combined_model.predict(X_train.compute())

    np.testing.assert_allclose(y_hat.get(),
                               y_train.compute().get(),
                               atol=1e-3,
                               rtol=1e-3)
Ejemplo n.º 3
0
def test_check_internal_model_failures(client):

    # Test model not trained yet
    model = LinearRegression(client=client)
    assert model.get_combined_model() is None

    # Test single Int future fails
    int_future = client.submit(lambda: 1)
    with pytest.raises(ValueError):
        model._set_internal_model(int_future)

    # Test list Int future fails
    with pytest.raises(ValueError):
        model._set_internal_model([int_future])

    # Test directly setting Int fails
    with pytest.raises(ValueError):
        model._set_internal_model(1)