handson-ml2 icon indicating copy to clipboard operation
handson-ml2 copied to clipboard

[Chapter 10] 'RandomizedSearchCV' object has no attribute 'best_estimator_'

Open simbol01 opened this issue 5 years ago • 3 comments

Help please I got this error while trying to save my model after fine-tuning with RandomizedSearchCV. model = rnd_search_cv.best_estimator_.model But I got the above error, any suggestions please?

simbol01 avatar Aug 10 '20 21:08 simbol01

I got the same error

danielbrito91 avatar Apr 17 '21 18:04 danielbrito91

Thanks for your feedback. The best_estimator_ attribute ends with an underscore. In Scikit-Learn, this means that it's a learned parameter, so it's only available after the fit() function finishes successfully. If there was an error during training, or if you interrupted training, then this attribute will not be present.

Note that the RandomizedSearchCV's fit() function will first look for the best hyperparameter values and then (if refit=True, which is the default) it will train a final model on the whole training set (instead of a cross-validation subset as during the hyperparameter search). So if the function was interrupted after the hyperparameter search but before the end of training the final model, it might be possible to have best_params_ defined, perhaps also best_score_, but not best_estimator_.

I hope this helps.

ageron avatar May 27 '21 06:05 ageron

Note: just to make sure, I just ran the Colab Notebook for this chapter, and best_estimator_ worked fine, so I think the hypothesis above is correct (the fit() function was probably interrupted before it finished).

ageron avatar May 27 '21 06:05 ageron