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() should not make deep copy of all parameters

See original GitHub issue

duplicate #5563 related to #9696

Describe the workflow you want to enable

sklearn.base.clone does not raise a RunTimeError when the constructor alters the model parameters

Describe your proposed solution

Delete lines 75-82 in sklearn/base.py

Describe alternatives you’ve considered, if relevant

I currently alter parameters in other methods, and there is no complaint. Since lines 75-82 don’t prevent me from altering the parameters, and they force me to hide that functionality in other methods, they are counterproductive.

It is a normal python practice to set defaults by accepting None as a parameter, and then if the value is None, to set the parameter to be some other thing. It is not clear what is gained by preventing this behavior. Specifically, sklearn exposes interfaces that are very helpful when building pipelines with my own custom models. This particular behavior makes building my custom modules hard.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
glemaitrecommented, Jan 17, 2020

I think what is more appropriate is to have a deepcopy parameter in clone to trigger or not copies of parameters.

I think that we have an issue about this in the past: https://github.com/scikit-learn/scikit-learn/issues/5563. I started at some point a PR https://github.com/scikit-learn/scikit-learn/pull/9696 as well, which should be rebased and handle properly the cloning in the GridSearchCV.

Then the assertion in clone will happen only when a deepcopy is required.

1reaction
glemaitrecommented, Jan 17, 2020

I reopen the issue and tag it as a duplicate.

Read more comments on GitHub >

github_iconTop Results From Across the Web

sklearn.base.clone — scikit-learn 1.2.0 documentation
Clone does a deep copy of the model in an estimator without actually copying attached data. It returns a new estimator with the...
Read more >
How to clone an scikit-learn estimator including its data?
sklearn.base.clone only clones an estimators parameters, not it's data, so is not useful in this case. Performing a partial fit on the clone...
Read more >
How to copy/clone scikit-learn estimator | Antardata
Depends on the use cases, the way you want to copy the scikit-learn model may be different. In my case, last week, I...
Read more >
sklearn.base — pystruct 0.2.4 documentation
Clone does a deep copy of the model in an estimator without actually copying ... a new estimator with the same parameters that...
Read more >
sklearn.base — pyts 0.12.0 documentation - Read the Docs
Clone does a deep copy of the model in an estimator without actually ... a new estimator with the same parameters that has...
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