Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow sklearn grid search over parameters specified as kwargs #3791

Merged
merged 2 commits into from
Oct 13, 2018

Conversation

RAMitchell
Copy link
Member

No description provided.

@RAMitchell RAMitchell requested a review from hcho3 October 13, 2018 01:44
@hcho3
Copy link
Collaborator

hcho3 commented Oct 13, 2018

"Allow sklearn grid search over parameters specified as kwargs"

Can you post a short snippet to show how grid search could be done? I'd like to see an example and see how this patch helps.

@RAMitchell
Copy link
Member Author

    from sklearn.model_selection import GridSearchCV
    from sklearn import datasets

    params = {'tree_method': 'hist'}
    clf = xgb.XGBClassifier(n_estimators=1, learning_rate=1.0,**params)
    assert clf.get_params()['tree_method'] == 'hist'
    # 'max_leaves' is not a default argument of XGBClassifier
    # Check we can still do grid search over this parameter
    search_params = {'max_leaves':range(2,5)}
    grid_cv = GridSearchCV(clf, search_params, cv=5)
    iris = datasets.load_iris()
    grid_cv.fit(iris.data, iris.target)

    # Expect unique results for each parameter value
    # This confirms sklearn is able to successfully update the parameter
    means = grid_cv.cv_results_['mean_test_score']
    assert len(means) == len(set(means))

I have added this example to the python tests. Before this patch the GridSearchCV class could not modify the parameters specified as kwargs. If you do a grid search on these parameters nothing will change at each iteration. This works with the patch.

@RAMitchell RAMitchell merged commit 5d6baed into dmlc:master Oct 13, 2018
CodingCat pushed a commit to CodingCat/xgboost that referenced this pull request Oct 25, 2018
alois-bissuel pushed a commit to criteo-forks/xgboost that referenced this pull request Dec 4, 2018
@RAMitchell RAMitchell deleted the grid-search branch December 6, 2018 19:33
@lock lock bot locked as resolved and limited conversation to collaborators Mar 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants