John M.
John M.

Reputation: 875

GridSearchCV final model

If I use GridSearchCV in scikit-learn library to find the best model, what will be the final model it returns? That said, for each set of hyper-parameters, we train the number of CV (say 3) models. In this way, will the function return the best model in those 3 models for the best setting of parameters?

Upvotes: 6

Views: 8624

Answers (2)

user3109582
user3109582

Reputation: 81

This is given in sklearn:

“The refitted estimator is made available at the best_estimator_ attribute and permits using predict directly on this GridSearchCV instance.”

So, you don’t need to fit the model again. You can directly get the best model from best_estimator_ attribute

Upvotes: 2

Yilun Zhang
Yilun Zhang

Reputation: 9008

The GridSearchCV will return an object with quite a lot information. It does return the model that performs the best on the left-out data:

best_estimator_ : estimator or dict

Estimator that was chosen by the search, i.e. estimator which gave highest score (or smallest loss if specified) on the left out data. Not available if refit=False.

Note that this is not the model that's trained on the entire data. That means, once you are confident that this is the model you want, you will need to retrain the model on the entire data by yourself.

Ref: http://scikit-learn.org/stable/modules/generated/sklearn.model_selection.GridSearchCV.html

Upvotes: 8

Related Questions