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

Feature Request: customizable early_stopping_tolerance #2526

Closed
kryptonite0 opened this issue Oct 24, 2019 · 9 comments · Fixed by #4580
Closed

Feature Request: customizable early_stopping_tolerance #2526

kryptonite0 opened this issue Oct 24, 2019 · 9 comments · Fixed by #4580

Comments

@kryptonite0
Copy link

I have a situation where the default numerical tolerance (0.001) for early stopping is too large. My target has a gamma distribution and the LGB Regressor reaches convergence too early, when the numerous low target values are well approximated by the model, but the few large values are still underestimated. When I deactivate early stopping, I can see the loss metric still improving at the 4th or more decimal digit, past the best iteration reached during early stopping. It would be great to be able to set manually the tolerance.

@StrikerRUS
Copy link
Collaborator

@kryptonite0 Can you please provide a reproducible example or training logs at least?

As I know, we do not have any default numerical tolerance. Refer to:

if best_score_list[i] is None or cmp_op[i](score, best_score[i]):

https://docs.python.org/3/library/operator.html#operator.lt

Linking dmlc/xgboost#4982 here.

@StrikerRUS
Copy link
Collaborator

Ping @kryptonite0

As you can see from examples, there is no "default numerical tolerance (0.001)":

gbm = lgb.train(params,
lgb_train,
num_boost_round=10,
valid_sets=lgb_train, # eval training data
feature_name=feature_name,
categorical_feature=[21])
print('Finished first 10 rounds...')

[1]	training's binary_logloss: 0.680894
[2]	training's binary_logloss: 0.672151
[3]	training's binary_logloss: 0.664753
[4]	training's binary_logloss: 0.656185
[5]	training's binary_logloss: 0.648174
[6]	training's binary_logloss: 0.641671
[7]	training's binary_logloss: 0.635597
[8]	training's binary_logloss: 0.628874
[9]	training's binary_logloss: 0.622432
[10]	training's binary_logloss: 0.616403
Finished first 10 rounds...

@StrikerRUS
Copy link
Collaborator

At present we do not have any "default numerical tolerance". But having customizable early stopping tolerance might be useful in some cases.

@StrikerRUS
Copy link
Collaborator

Closed in favor of being in #2302. We decided to keep all feature requests in one place.

Welcome to contribute this feature! Please re-open this issue (or post a comment if you are not a topic starter) if you are actively working on implementing this feature.

@jmoralez
Copy link
Collaborator

Hi. I'm working on this, I'll make a PR soon.

@jmoralez jmoralez reopened this Aug 27, 2021
@StrikerRUS
Copy link
Collaborator

Corresponding XGBoost experience:
Issue: dmlc/xgboost#4982
PR: dmlc/xgboost#6942
Further improvement: dmlc/xgboost#7137

@jmoralez
Copy link
Collaborator

Thanks for that. I believe my approach is the same as dmlc/xgboost#7137, basically the change I made was replacing operator.gt here:


with:

def _gt_threshold(curr_score, best_score, threshold):
    return curr_score > best_score + threshold

and the opposite for the minimize case (curr_score < best_score - threshold). I named the parameter early_stopping_threshold in train, cv and still had to modify sklearn.py and the docs.

StrikerRUS added a commit that referenced this issue Nov 10, 2021
* initial changes

* initial version

* better handling of cases

* warn only with positive threshold

* remove early_stopping_threshold from high-level functions

* remove remaining early_stopping_threshold

* update test to use callback

* better handling of cases

* rename threshold to min_delta

enhance parameter description

update tests

* Apply suggestions from code review

Co-authored-by: Nikita Titov <nekit94-08@mail.ru>

* reduce num_boost_round in tests

* Apply suggestions from code review

Co-authored-by: Nikita Titov <nekit94-08@mail.ru>

* trigger ci

Co-authored-by: Nikita Titov <nekit94-08@mail.ru>
Co-authored-by: Nikita Titov <nekit94-12@hotmail.com>
@StrikerRUS
Copy link
Collaborator

#4580 implemented this feature request for Python-package. Thank you very much @jmoralez !
I think we should reuse this issue as a feature request for adding the same functionality into R-package and core cpp code to not split the discussion. Refer to #4580 (comment). So, I'm not excluding this issue from #2302 for now.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity since it was closed.
To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues
including a reference to this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants