fix(model): upgrade LightGBM API usage to modern callbacks (#904) - #2347
Open
Yash Dharmendra Parmar (Yashparmar1125) wants to merge 1 commit into
Open
Conversation
- Replace deprecated LightGBM parameters (early_stopping_rounds, verbose_eval, evals_result) in documentation with callbacks - Add helper _parse_callbacks to safely construct callbacks list - Handle early_stopping_rounds=None safely without raising TypeError - Support custom callbacks passed via kwargs in LGBModel and HFLGBModel - Support kwargs in finetune() across LGBModel and HFLGBModel - Add unit tests for LightGBM callback and model compatibility
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
This PR modernizes LightGBM API usage across Qlib and updates related documentation and models to eliminate deprecation warnings from legacy arguments:
lgb.trainparameters (early_stopping_rounds,verbose_eval,evals_result) with modern callback objects (lgb.early_stopping,lgb.log_evaluation,lgb.record_evaluation)._parse_callbacksto cleanly construct callback lists and avoid redundant boilerplate across LightGBM models.early_stopping_rounds=Nonewithout raisingTypeError: early_stopping_round should be an integer. Got 'NoneType'.verbose_evalfor both boolean values (True/False) and integer periods.callbacksvia**kwargsintofit()andfinetune()without causing duplicate keyword argument errors.docs/start/integration.rstto demonstrate modern callback-based training.tests/model/test_lightgbm.py.Motivation and Context
Resolves #904
In recent versions of LightGBM (v3.3+ and v4.x), passing parameters like
early_stopping_rounds,verbose_eval, andevals_resultdirectly tolgb.trainemitsUserWarningdeprecation messages and can cause runtime exceptions when early stopping is disabled (None). This PR brings Qlib's LightGBM integration in line with modern standards while maintaining full backward compatibility.How Has This Been Tested?
pytest qlib/tests/test_all_pipeline.pyunder upper directory ofqlib.Ran test suites and style checks:
pytest tests/model/test_lightgbm.py tests/test_contrib_model.py -v(5/5 passed)black --check qlib/contrib/model/gbdt.py qlib/contrib/model/highfreq_gdbt_model.py tests/model/test_lightgbm.py -l 120(clean)flake8 --ignore=E501,E266,E402,W503,E731,E203 --per-file-ignores="__init__.py:F401,F403" qlib/contrib/model/gbdt.py qlib/contrib/model/highfreq_gdbt_model.py tests/model/test_lightgbm.py(0 warnings)Screenshots of Test Results (if appropriate):