Fix GPU RF (#6755)

* Fix sampling.
This commit is contained in:
Jiaming Yuan
2021-03-17 06:23:35 +08:00
committed by GitHub
parent 1a73a28511
commit 4f75f514ce
4 changed files with 26 additions and 9 deletions

View File

@@ -357,23 +357,26 @@ def test_boston_housing_regression():
assert mean_squared_error(preds4, labels) < 350
def test_boston_housing_rf_regression():
def run_boston_housing_rf_regression(tree_method):
from sklearn.metrics import mean_squared_error
from sklearn.datasets import load_boston
from sklearn.model_selection import KFold
boston = load_boston()
y = boston['target']
X = boston['data']
X, y = load_boston(return_X_y=True)
kf = KFold(n_splits=2, shuffle=True, random_state=rng)
for train_index, test_index in kf.split(X, y):
xgb_model = xgb.XGBRFRegressor(random_state=42).fit(
X[train_index], y[train_index])
xgb_model = xgb.XGBRFRegressor(random_state=42, tree_method=tree_method).fit(
X[train_index], y[train_index]
)
preds = xgb_model.predict(X[test_index])
labels = y[test_index]
assert mean_squared_error(preds, labels) < 35
def test_boston_housing_rf_regression():
run_boston_housing_rf_regression("hist")
def test_parameter_tuning():
from sklearn.model_selection import GridSearchCV
from sklearn.datasets import load_boston