-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
[python-package] mark EarlyStopException as part of public API #6095
Conversation
@@ -32,5 +32,5 @@ | |||
'train', 'cv', | |||
'LGBMModel', 'LGBMRegressor', 'LGBMClassifier', 'LGBMRanker', | |||
'DaskLGBMRegressor', 'DaskLGBMClassifier', 'DaskLGBMRanker', | |||
'log_evaluation', 'record_evaluation', 'reset_parameter', 'early_stopping', | |||
'log_evaluation', 'record_evaluation', 'reset_parameter', 'early_stopping', 'EarlyStopException', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allows for imports like
from lightgbm import EarlyStopException
or
import lightgbm as lgb
def _early_stop(env):
raise lgb.EarlyStopException(
best_iteration=6,
best_score=[("some_validation_set", "some_metric", 0.708, True)]
)
Every other part of the public API can be imported like this, and I think such imports should be encouraged over those that require knowing the internal sub-module structure like from lightgbm.callback import EarlyStopException
This pull request 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. |
Doing some research for another contribution, I found that several large projects rely on importing
lightgbm.callback.EarlyStopException
, and using it to trigger early stopping in LightGBM.autogluon
: https://github.com/autogluon/autogluon/blob/f77a7b4ea2f6140685e73ef41f3b533cea272391/tabular/src/autogluon/tabular/models/lgb/callbacks.py#L8FLAML
: https://github.com/microsoft/FLAML/blob/4886cb56891af6ccf3e6d694bd97f571623fa6f8/flaml/automl/model.py#L1430This PR proposes formally marking that class (and by extension, that mechanism of triggering early stopping) as a part of the public API, to prevent it from being removed or altered in a non-backward-compatible way in the future.