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

Chapter 6, page 203 #113

Closed
GermanCM opened this issue Oct 21, 2019 · 3 comments
Closed

Chapter 6, page 203 #113

GermanCM opened this issue Oct 21, 2019 · 3 comments

Comments

@GermanCM
Copy link

GermanCM commented Oct 21, 2019

Dear professor Sebastian,

I think there is no need to retrain the best estimator with the train set after using 'GridSearchCV', since the 'GridSearchCV' class already implements, by default (with the 'refit' param = True by default), a model re-training on the whole train dataset with the best found hyperparameters (based on the defined metric).
So in your example in this page, we could implement directly:
clf = gs.best_estimator_
--> this line would not be necessary: clf.fit(X_train, y_train)
print('Test accuracy: %.3f' % clf.score(X_test, y_test))
Test accuracy: 0.974

I hope I explained this clearly.
Best regards and thanks for your excellent book.

Germán

@rasbt
Copy link
Owner

rasbt commented Oct 21, 2019

Hi Germán,

you are absolutely right. I think I listed this as two independent steps to make the general workflow/concept more clear (independent of scikit-learn). However, you can set refit=True to achieve the same effect. Computationally, it should make no difference in terms of how expensive it is to run the code. Thanks for the note though, I should mention this.

@rasbt
Copy link
Owner

rasbt commented Oct 22, 2019

Oh I see that the clf.fit(X_train, y_train) is completely redundant since it's refit=True by default as you correctly pointed out!

Edit: just clarified this in the notebook. Thanks!

@GermanCM
Copy link
Author

Thanks dear Sebastian for including a note about this in your third edition, I will close the issue :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants