From 5dd23a21959f5cb7e9d946f5e33a4f5b1d94f32b Mon Sep 17 00:00:00 2001 From: terrytangyuan Date: Sun, 4 Oct 2015 23:16:00 -0500 Subject: [PATCH] TST: Added test for parameter tuning using GridSearchCV --- tests/python/test_with_sklearn.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/python/test_with_sklearn.py b/tests/python/test_with_sklearn.py index 7fd3c88cc..067b166af 100644 --- a/tests/python/test_with_sklearn.py +++ b/tests/python/test_with_sklearn.py @@ -42,5 +42,16 @@ def test_boston_housing_regression(): labels = y[test_index] assert mean_squared_error(preds, labels) < 9 +def test_parameter_tuning(): + boston = load_boston() + y = boston['target'] + X = boston['data'] + xgb_model = xgb.XGBRegressor() + clf = GridSearchCV(xgb_model, + {'max_depth': [2,4,6], + 'n_estimators': [50,100,200]}, verbose=1) + clf.fit(X,y) + assert clf.best_score_ < 0.7 + assert clf.best_params_ == {'n_estimators': 100, 'max_depth': 4}