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

Expose number of bins used by the model while binning continuous features to C API #3406

Closed
narendramukherjee opened this issue Sep 23, 2020 · 6 comments · Fixed by #5048
Closed

Comments

@narendramukherjee
Copy link

narendramukherjee commented Sep 23, 2020

Hi,

I am using the sklearn api to lightgbm, and am wondering if there's a way I can get the number of bins (defined to be < max_bin) that the model creates while binning continuous features? I found the cpp code that counts up the bins (in num_bin_) here: https://github.com/Microsoft/LightGBM/blob/7a89d0054bcf0db9f96af3c53a078b6aa3152efe/src/io/bin.cpp#L207-L401 , going from #2063 , but is there a way to get this number from a trained model for each feature it binned?

Thanks in advance for any help!

@guolinke
Copy link
Collaborator

sorry, this api is not exposed. Exposing it is relatively easy, contribution is very welcome!

@narendramukherjee
Copy link
Author

Thanks @guolinke - can you give me some pointers on how to go about exposing this part of the api? I can then make an appropriate PR

@guolinke
Copy link
Collaborator

you can add the related function in c_api.h and c_api.cpp.
like

LightGBM/src/c_api.cpp

Lines 1486 to 1492 in ceb6265

int LGBM_DatasetGetNumData(DatasetHandle handle,
int* out) {
API_BEGIN();
auto dataset = reinterpret_cast<Dataset*>(handle);
*out = dataset->num_data();
API_END();
}

@StrikerRUS StrikerRUS changed the title How to get the number of bins used by the model while binning continuous features? Expose number of bins used by the model while binning continuous features to C API Mar 7, 2021
@StrikerRUS
Copy link
Collaborator

Closed in favor of being in #2302. We decided to keep all feature requests in one place.

Welcome to contribute this feature! Please re-open this issue (or post a comment if you are not a topic starter) if you are actively working on implementing this feature.

@jmoralez
Copy link
Collaborator

jmoralez commented Mar 3, 2022

Reopening since I'm working on this.

@github-actions
Copy link

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 github-actions bot locked as resolved and limited conversation to collaborators Aug 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants