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

loading lightgbm.basic.Booster #539

Closed
marsupialtail opened this issue Aug 12, 2021 · 6 comments · Fixed by #540
Closed

loading lightgbm.basic.Booster #539

marsupialtail opened this issue Aug 12, 2021 · 6 comments · Fixed by #540

Comments

@marsupialtail
Copy link
Contributor

Is there a way to directly convert a LightGBM booster object instead of using the sklearn API?

With the sklearn API for lgb, I think you can only load file to a booster object, and I'm not sure how to initialize a lgb regressor from a booster object.

Currently when I try convert booster object directly I get: hummingbird.ml.exceptions.MissingConverter: Unable to find converter for model type <class 'lightgbm.basic.Booster'>.

@ksaur
Copy link
Collaborator

ksaur commented Aug 12, 2021

Right now we only support direct conversion from LGBM Classifier/Ranker/Regressor, so the error you get is expected.

I'm not sure how much additional effort it would be to support lightgbm.Booster; I'll add it to feature requests list.

Other thoughts @interesaaat ?

@interesaaat
Copy link
Collaborator

Hey! I think it should be doable. I saw that we get all infos from the booster_ object.

image

@marsupialtail I think it is a matter of adding LightGBM booster among the supported operators. Do you want to give it a shot?

@marsupialtail
Copy link
Contributor Author

If you point me to a couple places in the code you think would serve as a good reference, I can try to work on this.

@ksaur
Copy link
Collaborator

ksaur commented Aug 13, 2021

@marsupialtail - PR #173 (LGBMRanker) is a good starting point! For Booster, you'll probably need to add a separate converter function in hummingbird/ml/operator_converters/lightgbm.py. (For the Ranker one in the PR, it was able to reuse the convert_sklearn_lgbm_regressor.)

I'm not sure what else will be needed, but as Matteo showed above, the information will be there in line 99.

Please reach out if you get stuck!

@marsupialtail
Copy link
Contributor Author

I made a PR. Please review. Thanks.

@ksaur ksaur linked a pull request Aug 23, 2021 that will close this issue
@alexyar88
Copy link

You can create sklearn object from your booster. Something like that:

lgb_clf = lgb.LGBMClassifier(n_estimators=booster.current_iteration())
lgb_clf._Booster = deepcopy(booster)
lgb_clf._n_features = len(booster.feature_name())
lgb_clf._n_classes = len(np.unique(y))
lgb_clf._le = _LGBMLabelEncoder().fit(y)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants