sklearn.base.clone - incorrect/unclear error about 'get_params' when called on class
See original GitHub issueDescribe the bug
When I clone a class, rather than instance of that class, I get error message saying that ‘get_params is not implemented’, even though it is
Steps/Code to Reproduce
from sklearn.base import clone
from sklearn.linear_model import LogisticRegression
clone(LogisticRegression)
Expected Results
# TypeError Cannot clone object '<class 'sklearn.linear_model.logistic.LogisticRegression'>' (type <class 'type'>): it is a class rather than an instance of a class.
Actual Results
# TypeError: Cannot clone object '<class 'sklearn.linear_model.logistic.LogisticRegression'>' (type <class 'type'>): it does not seem to be a scikit-learn estimator as it does not implement a 'get_params' methods.
LogisticRegression.get_params
# <function sklearn.base.BaseEstimator.get_params(self, deep=True)>
This should be quite straightforward to fix, we could just change the comparison here to two different comparisons with different warnings. The current warning is unclear, and makes debugging harder.
Versions
System: python: 3.7.4 (default, Aug 13 2019, 15:17:50) [Clang 4.0.1 (tags/RELEASE_401/final)] executable: /opt/anaconda3/bin/python machine: Darwin-18.7.0-x86_64-i386-64bit
Python deps: pip: 19.2.3 setuptools: 41.4.0 sklearn: 0.21.3 numpy: 1.17.2 scipy: 1.3.1 Cython: 0.29.13 pandas: 0.25.1
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
sklearn.base.clone — scikit-learn 1.2.0 documentation
Construct a new unfitted estimator with the same parameters. Clone does a deep copy of the model in an estimator without actually copying...
Read more >Python scikit-learn: Cannot clone object... as the constructor ...
This seems to be a problem in the equality check between the instance of the class and its copy created by sklearn.base.clone because ......
Read more >sklearn.base — gplearn 0.4.2 documentation - Read the Docs
__class__ new_object_params = estimator.get_params(deep=False) for name, ... lines class BaseEstimator: """Base class for all estimators in scikit-learn.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@glemaitre Thanks, yes I’ll do that soon just working out how to clone repo, run tests ect.
@olicairns do you want to propose a PR?