- Notifications
You must be signed in to change notification settings - Fork 25.8k
BUG fix SparseCoder to follow scikit-learn API and allow cloning#17679
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
Conversation
Uhm did something about this one. Let me check. |
Found it: #16346 |
Let me know which one you prefer. PR #16346 does not test cloning and that's what caused the issue. I recommend adding one more test. |
I think this is important to make the estimator scikit-learn compliant (it will crash soon otherwise). Cloning is part of that so we should merge both PR. Could you merge my PR inside yours like this you supersede mine? I will review it then. |
I just solve the conflicts in mine so you should have no so much trouble to merge them. |
ok :) |
Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
@sdpython I will do a review. I think that we might need to add some of the test (usually done in common test) but that require specific shape for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments but otherwise LGTM. I don't think there is an easy way to re-add SparseCoder
to test_common
as it requires to specify the dictionary in the constructor params and the dictionary shape should be consistent with X.shape[1]
.
We would need to have something like that (it is only the transformer). deftest_sparse_coder_common_transformer(): fromfunctoolsimportpartialfromsklearn.utils.estimator_checksimportcheck_transformer_data_not_an_arrayfromsklearn.utils.estimator_checksimportcheck_transformer_generalfromsklearn.utils.estimator_checksimportcheck_transformers_unfittedrng=np.random.RandomState(777) n_components, n_features=40, 3init_dict=rng.rand(n_components, n_features) sc=SparseCoder(init_dict) check_transformer_data_not_an_array(sc.__class__.__name__, sc) check_transformer_general(sc.__class__.__name__, sc) check_transformer_general_memmap=partial( check_transformer_general, readonly_memmap=True ) check_transformer_general_memmap(sc.__class__.__name__, sc) check_transformers_unfitted(sc.__class__.__name__, sc) |
I think this is wiser to merge with the current test and see how the |
I have encountered this while working on other estimators outside sklearn, and it's partly why I wanted to have a better way of telling common tests now to generate required data for certain tests. |
Added. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks @sdpython!
There is a single thing missing which is an entry in what's new because we are deprecated one parameter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@glemaitre merge if happy
thx @sdpython
actually @glemaitre had approved so go ! thx @sdpython |
I will make a PR adding the deprecation in what's new :) |
…kit-learn#17679) * BUG fix SparseCoder to follow scikit-learn API * TST check that get_params and set_params work as expected * address comments * PEP8 * iter * Fixesscikit-learn#8675, fix cloning for SparseCoder * remove spaces * Update _dict_learning.py * fix confusing arguments * remove unnecessary code * Update test_common.py * removes spaces * PEP8 * iter * fix merge * ignore a mypy warning * type: ignore * remove one deprecated verification * Update sklearn/decomposition/_dict_learning.py Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com> * Update sklearn/decomposition/_dict_learning.py Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com> * Update sklearn/decomposition/tests/test_dict_learning.py Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com> * test clone produces different id * review * add one more test * lint * Update sklearn/decomposition/tests/test_dict_learning.py Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com> Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org>
…kit-learn#17679) * BUG fix SparseCoder to follow scikit-learn API * TST check that get_params and set_params work as expected * address comments * PEP8 * iter * Fixesscikit-learn#8675, fix cloning for SparseCoder * remove spaces * Update _dict_learning.py * fix confusing arguments * remove unnecessary code * Update test_common.py * removes spaces * PEP8 * iter * fix merge * ignore a mypy warning * type: ignore * remove one deprecated verification * Update sklearn/decomposition/_dict_learning.py Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com> * Update sklearn/decomposition/_dict_learning.py Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com> * Update sklearn/decomposition/tests/test_dict_learning.py Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com> * test clone produces different id * review * add one more test * lint * Update sklearn/decomposition/tests/test_dict_learning.py Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com> Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org>
Reference Issues/PRs
Fixes#8675
Fixes#16336
Supersedes and closes#16346
What does this implement/fix? Explain your changes.
SparseCoder cannot be used in a GridSearchCV because it could not be cloned. A parameter in the constructor had a different meaning when stored in an instance (dictionary).