question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sklearn.base.clone - incorrect/unclear error about 'get_params' when called on class

See original GitHub issue

Describe 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:closed
  • Created 4 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
olicairnscommented, Jan 22, 2020

@glemaitre Thanks, yes I’ll do that soon just working out how to clone repo, run tests ect.

0reactions
glemaitrecommented, Jan 22, 2020

@olicairns do you want to propose a PR?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found