ageron / handson-ml2

A series of Jupyter notebooks that walk you through the fundamentals of Machine Learning and Deep Learning in Python using Scikit-Learn, Keras and TensorFlow 2.
Apache License 2.0
27.65k stars 12.69k forks source link

Grid Search Best Estimator #251

Open achang2 opened 3 years ago

achang2 commented 3 years ago

In both the book and the example on github, when using the grid search to find the best estimator, gridsearch.best_estimator returns something that looks like the following:

image

However, when I run the same thing on my local machine, all I get is this: image

So two questions. The first is why am I getting slightly different hyperparameters (I've seen it flip-flop between 6 and 8 for max_features). Is it because the folds are randomized, so the models that are trained are slightly different? And the second question is why in the output it only gives me the two hyperparameters I asked it search over, but not the rest. Is there some setting I'm missing?

abdoulsn commented 3 years ago

Hello which page in the book are you referencing?

achang2 commented 3 years ago

Sorry, I should have included that in my original post. I'm looking at Chapter 2, page 77

Praful932 commented 3 years ago

@achang2 It is just a matter of the output of scikit-learn. You can set the random_state parameter of the estimator to get same results each time. All other parameters except the ones you searched over are all intialized to the default value.

achang2 commented 3 years ago

@Praful932 Thanks, that makes sense. But what about showing all the other hyperparemeters (like bootstrap, min_samples_leaf, etc.)? Why aren't those showing up when I run them locally.

Praful932 commented 3 years ago

@achang2 My best guess is because all other parameters are the default ones. Take a look at the documentation. Also like I said it's the matter of the output of scikit. You could take a look at the source and If I am not wrong, the magic methods are the ones which decide the printable output.