-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
[python] how do I sub-class lightgbm.sklearn estimators and add new parameters? #5010
Comments
Thanks for using LightGBM, and for the excellent write-up with a reproducible example. There's at least one important difference between your example and what was described in https://github.com/microsoft/LightGBM/issues/3758#issuecomment-932684440....it looks like you want to add a NEW parameter, while #3758 was about sub-classing LightGBM in a way that changed how the values for EXISTING LightGBM parameters were set. If you want to add a new parameter to a scikit-learn estimator, it needs to be defined as a keyword argument in that estimator's signature. As mentioned in https://scikit-learn.org/stable/developers/develop.html#parameters-and-init
That means that if you want to add new parameters when sub-classing a For an example of this, please see the discussion around how
|
Hi @jameslamb. Thank you for the fast and very detailed reply. Much approeciated! The thing that confused me with using For example, this:
will print Based on the dask.py script, what I am doing wrong here is that I should be setting all the default values to the new parent class, and not expect to get them for free through inheritance. Is that correct? |
I just want to note that the root cause of
is the same as in #4518. Logging level is set after parameters parsing based on the parsed |
Thank you both for the replies. For completeness, I get the error even if I set the parameters at the
Then,
so, However, I still get the same error message
|
That warning is telling you that there is no LightGBM parameter called Since LightGBM/python-package/lightgbm/dask.py Lines 1017 to 1024 in d31346f
LightGBM/python-package/lightgbm/dask.py Lines 1047 to 1048 in d31346f
LightGBM/python-package/lightgbm/dask.py Line 1080 in d31346f
|
Thank you both! Much appreciate the detailed explanations. |
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. |
Description
Hi. I was trying to subclass the LGBMRegressor calls to create a customer training pipeline. To do so, I followed the discussion here on how to do it. This discussion pointed that passing new parameters to the new class should be done in
set_params
rather than__init__
.Doing so, leads to a warning error
[LightGBM] [Warning] Unknown parameter: test_param
which cannot be suppressed using verbosity = -1
Reproducible example
Environment info
LightGBM version or commit hash: 3.3.2
Command(s) you used to install LightGBM
Additional Comments
The text was updated successfully, but these errors were encountered: