def test_regressor(output, client, listen_port): X, y, w, dX, dy, dw = _create_data(objective='regression', output=output) dask_regressor = dlgbm.DaskLGBMRegressor(time_out=5, local_listen_port=listen_port, seed=42, num_leaves=10, tree='data') dask_regressor = dask_regressor.fit(dX, dy, client=client, sample_weight=dw) p1 = dask_regressor.predict(dX) if output != 'dataframe': s1 = r2_score(dy, p1) p1 = p1.compute() local_regressor = lightgbm.LGBMRegressor(seed=42, num_leaves=10) local_regressor.fit(X, y, sample_weight=w) s2 = local_regressor.score(X, y) p2 = local_regressor.predict(X) # Scores should be the same if output != 'dataframe': assert_eq(s1, s2, atol=.01) # Predictions should be roughly the same assert_eq(y, p1, rtol=1., atol=100.) assert_eq(y, p2, rtol=1., atol=50.) client.close()
def test_regressor_local_predict(client, listen_port): # noqa X, y, w, dX, dy, dw = _create_data('regression', output='array') a = dlgbm.LGBMRegressor(local_listen_port=listen_port, seed=42) a = a.fit(dX, dy, sample_weight=dw, client=client) p1 = a.predict(dX) p2 = a.to_local().predict(X) s1 = r2_score(dy, p1) p1 = p1.compute() s2 = a.to_local().score(X, y) print(s1) # Predictions and scores should be the same assert_eq(p1, p2) np.isclose(s1, s2)
def test_regressor_local_predict(loop, listen_port): with cluster() as (s, [a, b]): with Client(s['address'], loop=loop): X, y, w, dX, dy, dw = _create_data('regression', output="array") a = dlgbm.LGBMRegressor(local_listen_port=listen_port, seed=42) a = a.fit(dX, dy, sample_weight=dw) p1 = a.predict(dX) p2 = a.to_local().predict(X) s1 = r2_score(dy, p1) p1 = p1.compute() s2 = a.to_local().score(X, y) print(s1) # Predictions and scores should be the same assert_eq(p1, p2) np.isclose(s1, s2)
def test_regressor_local_predict(client, listen_port): X, y, w, dX, dy, dw = _create_data('regression', output='array') dask_regressor = dlgbm.DaskLGBMRegressor(local_listen_port=listen_port, seed=42) dask_regressor = dask_regressor.fit(dX, dy, sample_weight=dw, client=client) p1 = dask_regressor.predict(dX) p2 = dask_regressor.to_local().predict(X) s1 = r2_score(dy, p1) p1 = p1.compute() s2 = dask_regressor.to_local().score(X, y) # Predictions and scores should be the same assert_eq(p1, p2) assert_eq(s1, s2)
def test_regressor(output, client, listen_port): # noqa X, y, w, dX, dy, dw = _create_data('regression', output=output) a = dlgbm.LGBMRegressor(time_out=5, local_listen_port=listen_port, seed=42) a = a.fit(dX, dy, client=client, sample_weight=dw) p1 = a.predict(dX, client=client) if output != 'dataframe': s1 = r2_score(dy, p1) p1 = p1.compute() b = lightgbm.LGBMRegressor(seed=42) b.fit(X, y, sample_weight=w) s2 = b.score(X, y) p2 = b.predict(X) # Scores should be the same if output != 'dataframe': assert_eq(s1, s2, atol=.01) # Predictions should be roughly the same assert_eq(y, p1, rtol=1., atol=50.) assert_eq(y, p2, rtol=1., atol=50.)
def test_regressor_local_predict(client, listen_port): X, y, _, dX, dy, dw = _create_data('regression', output='array') dask_regressor = dlgbm.DaskLGBMRegressor(local_listen_port=listen_port, random_state=42, n_estimators=10, num_leaves=10, tree_type='data') dask_regressor = dask_regressor.fit(dX, dy, sample_weight=dw, client=client) p1 = dask_regressor.predict(dX) p2 = dask_regressor.to_local().predict(X) s1 = r2_score(dy, p1) p1 = p1.compute() s2 = dask_regressor.to_local().score(X, y) # Predictions and scores should be the same assert_eq(p1, p2) assert_eq(s1, s2) client.close()