Beispiel #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())
Beispiel #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)
Beispiel #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)
Beispiel #4
0
def test_mnmg():
    cluster = LocalCUDACluster(threads_per_worker=1)
    client = Client(cluster)
    n_workers = len(client.scheduler_info()['workers'])

    # Create and populate a GPU DataFrame
    df_float = cudf.DataFrame()
    df_float['0'] = [1.0, 2.0, 5.0]
    df_float['1'] = [4.0, 2.0, 1.0]
    df_float['2'] = [4., 2, 1]

    ddf_float = dask_cudf.from_cudf(df_float, npartitions=2*n_workers)

    X = ddf_float[ddf_float.columns.difference(['2'])]
    y = ddf_float['2']
    mod = LinearRegression()
    mod = mod.fit(X, y)

    actual_output = str(mod.predict(X).compute().values)
    expected_output = '[4. 2. 1.]'
    assert actual_output == expected_output