LightGBM icon indicating copy to clipboard operation
LightGBM copied to clipboard

[python-package] What is the best way for Booster to fit the Booster model to residuals?

Open johnkimdy opened this issue 3 years ago • 5 comments

I am trying to convert the DecisionTreeClassifier model by SciKit Learn to LGBM using the existing model specs. The only problem is that I would have to import the lgbm model using lgb.Booster, but this doesn't have the '.fit()' feature that Scikit-learn provides. What is the best alternative for the LGBM Booster model? refit, retrain, or update? Is there a way to replicate the model by using lightgbm.lgbmclassifier? Thanks,

johnkimdy avatar Jan 11 '23 22:01 johnkimdy

Thanks for using LightGBM!

The lightgbm Python package has a scikit-learn compatible interface.

See this example:

https://github.com/microsoft/LightGBM/blob/c2d2c99f44dcaad1f6dfc05d877e47aad13ddfc9/examples/python-guide/sklearn_example.py#L24-L30

and the docs at https://lightgbm.readthedocs.io/en/v3.3.4/pythonapi/lightgbm.LGBMClassifier.html

jameslamb avatar Jan 11 '23 22:01 jameslamb

Is there a way to access each individual tree and fit each tree separately? for Booster or sklearn LGBM?

johnkimdy avatar Feb 10 '23 19:02 johnkimdy

@johnkimdy what do you mean by "fit each tree separately", exactly?

LightGBM training builds an ensemble of trees.

jameslamb avatar Mar 06 '23 04:03 jameslamb

@johnkimdy what do you mean by "fit each tree separately", exactly?

LightGBM training builds an ensemble of trees.

can we run LGBMRegressor iteratively for each individual tree to replicate lgb.train? Is LGBMRegressor the counterpart of decisiontreeregressor in sklearn?

johnkimdy avatar Mar 07 '23 15:03 johnkimdy

@johnkimdy sorry for the delayed response.

No, LGBMRegressor.fit() fits an ensemble of trees, meaning a collection of multiple trees whose output is combined to produce a prediction.

The closest equivalent in scikit-learn is sklearn.ensemble.HistGradientBoostingRegressor (docs).

jameslamb avatar Jul 06 '23 02:07 jameslamb

This issue has been automatically closed because it has been awaiting a response for too long. When you have time to to work with the maintainers to resolve this issue, please post a new comment and it will be re-opened. If the issue has been locked for editing by the time you return to it, please open a new issue and reference this one. Thank you for taking the time to improve LightGBM!

github-actions[bot] avatar Aug 05 '23 04:08 github-actions[bot]

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[bot] avatar Nov 08 '23 00:11 github-actions[bot]