[python-package] mark EarlyStopException as part of public API#6095
Merged
[python-package] mark EarlyStopException as part of public API#6095
Conversation
jameslamb
commented
Sep 13, 2023
| 'LGBMModel', 'LGBMRegressor', 'LGBMClassifier', 'LGBMRanker', | ||
| 'DaskLGBMRegressor', 'DaskLGBMClassifier', 'DaskLGBMRanker', | ||
| 'log_evaluation', 'record_evaluation', 'reset_parameter', 'early_stopping', | ||
| 'log_evaluation', 'record_evaluation', 'reset_parameter', 'early_stopping', 'EarlyStopException', |
Collaborator
Author
There was a problem hiding this comment.
This allows for imports like
from lightgbm import EarlyStopExceptionor
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
jmoralez
approved these changes
Sep 13, 2023
Collaborator
Author
Contributor
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.