-
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
LightGBM does not comply with sklearn's check_is_fitted #3014
Comments
@romanlutz My ones are
Which indicates the wrong way of usage. Adding required argument I have no errors:
UPD: You can use |
OK, seems the problem is in that in Anyway, a fix above works fine with new versions ( |
Wow, thanks for your quick response! I can confirm that I'm getting the same TypeError that you got when I downgrade to 0.21.3 Looks like it became optional with this change about 4 months ago: https://github.com/scikit-learn/scikit-learn/pull/15947/files |
Weird! I just installed scikit-learn from conda and lightgbm from nightly artifacts and have no problems...
|
I don't see the issue with
either (regardless of the version I'm using), but if you remove the second argument it shows up. I guess I'm not familiar enough with LGBM to tell, but shouldn't it work without that extra arg? From what I understand about |
The part which does the check in sklearn is: if attributes is not None:
if not isinstance(attributes, (list, tuple)):
attributes = [attributes]
attrs = all_or_any([hasattr(estimator, attr) for attr in attributes])
else:
attrs = [v for v in vars(estimator)
if v.endswith("_") and not v.startswith("__")]
if not attrs:
raise NotFittedError(msg % {'name': type(estimator).__name__}) And the issue is that Also, these @ogrisel @rth @NicolasHug WDYT? |
On the contrary - rather than upgrading the environment, you need to pin all packages used by LightGBM, including sklearn to old versions from 6 months ago when the "current" (latest) LightGBM release was built. There are more and more API discrepancies with the recent versions of sklearn... @StrikerRUS : a release is long overdue... |
Hello @adrinjalali ! Have scikit-learn team made any decision for using properties as indicators of fitted estimators: #3014 (comment)? Also, it looks like internally some scikit-learn estimators uses properties for some attributes ( |
The But we also have had discussions regarding moving away from those properties and using methods instead where there is an implicit computation behind the property. A workaround for I haven't seen a discussion happening around accepting properties in |
@adrinjalali Thanks a lot for your reply and proposed workaround! I think we can go with it for now, while deeper refactoring will be done under #2966. I'm just confused by the following inconsistency. When you call I believe behavior of
|
Hi, Is this problem already fixed? I use LightGBM version 3.0.0, and scikit-learn version 0.23.2. Or, in order to fix this error, should we keep using the workaround check_is_fitted(lgbmc, ['n_features_']) ? |
Hello @GlorianY ! The problem is fixed in the |
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. |
Environment info:
Operating System: Windows 10
CPU/GPU model: Processor Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz, 2112 Mhz, 4 Core(s), 8 Logical Processor(s)
C++/Python/R version: 3.7.4
LightGBM version or commit hash: 2.3.1
Error message
sklearn.exceptions.NotFittedError: This LGBMClassifier instance is not fitted yet. Call 'fit' with appropriate arguments before using this estimator.
Reproducible examples
see below
Steps to reproduce
The text was updated successfully, but these errors were encountered: