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

gbm.best_iteration_ is None when early_stopping_round = 3 in sklearn API #1181

Closed
startakovsky opened this issue Jan 8, 2018 · 5 comments
Closed

Comments

@startakovsky
Copy link

The code in the image below indicates that in the sklearn API, best_iteration_ is not set even when early_stopping_round > 0.

Is this expected behavior?

image

@guolinke
Copy link
Collaborator

guolinke commented Jan 8, 2018

@startakovsky
I think early_stopping_rounds is in fit function: https://github.com/Microsoft/LightGBM/blob/master/python-package/lightgbm/sklearn.py#L295-L300 .
Not the early_stopping_round in Constructor.

ping @StrikerRUS @wxchan
However, I am confused about why early stopping is working in @startakovsky 's case.
BTW, why best_score is set independently ? https://github.com/Microsoft/LightGBM/blob/master/python-package/lightgbm/sklearn.py#L478-L481

updated:
I think the reason is:
https://github.com/Microsoft/LightGBM/blob/master/python-package/lightgbm/engine.py#L101-L105

@wxchan @StrikerRUS Should we have the same conversion in sklearn interface?

@startakovsky
Copy link
Author

startakovsky commented Jan 8, 2018

@guolinke the following does work... and for now I will use this approach to track gbm.best_iteration_. Just hoping it would also work when supplied to params (i.e. lgb.LGBMClassifier(**params).

image

@StrikerRUS
Copy link
Collaborator

@guolinke

BTW, why best_score is set independently ? https://github.com/Microsoft/LightGBM/blob/master/python-package/lightgbm/sklearn.py#L478-L481

The answer is #890.

@StrikerRUS
Copy link
Collaborator

@guolinke
Yeah, it seems that in this situation early_stopping_rounds is passed through params into train() and used there.

Should we have the same conversion in sklearn interface?

In my opinion, all users are adult enough to read the docstring and notice that early_stopping_rounds has own parameter and shouldn't be passed via **kwargs.

@guolinke
Copy link
Collaborator

guolinke commented Jan 8, 2018

@startakovsky I agree with @StrikerRUS . Logically, early_stopping_rounds is used to control the fit(training) process, so using it in fit is more reasonable.

@guolinke guolinke closed this as completed Jan 8, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Mar 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants