-
-
Notifications
You must be signed in to change notification settings - Fork 26k
ENH run common tests for SparseCoder #26691
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
base: main
Are you sure you want to change the base?
ENH run common tests for SparseCoder #26691
Conversation
4d8db48
to
3b8e328
Compare
:mod:`sklearn.decomposition` | ||
............................ | ||
|
||
- |Fix| :meth:`decomposition.SparseCoder.transform` now preserves data |
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.
It seems that you have changes that are not related to this PR.
:mod:`sklearn.utils` | ||
.................... | ||
|
||
- |Enhancement| :func:`utils.estimator_checks._construct_instance` now accepts |
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.
You don't need to have an entry for this change because it is changes internals only.
@@ -394,3 +394,37 @@ def predict_proba(self, X): | |||
@available_if(_check_response("decision_function")) | |||
def decision_function(self, X): | |||
return "decision_function" | |||
|
|||
|
|||
class DictionaryRequiringEstimatorMock(BaseEstimator): |
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.
There is not need for a mock
@@ -435,14 +446,13 @@ def _construct_instance(Estimator): | |||
("est2", LogisticRegression(C=1)), | |||
] | |||
) | |||
elif required_parameters in (["dictionary"],): |
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.
no need for the "dictionary" part but only check for the SparseCoder
@@ -1249,6 +1281,12 @@ def check_dtype_object(name, estimator_orig): | |||
estimator = clone(estimator_orig) | |||
y = _enforce_estimator_tags_y(estimator, y) | |||
|
|||
# ensure n_features of dictionary == n_features of X for SparseCoder | |||
if name == "SparseCoder": |
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.
So it seems that the complex things here is to generate a dictionary that depends on X
ahead of time.
Maybe the least tricky way is to run check_estimator
not from the common test but from the test module and inherit from SparseCoder
a fit method that would generate the dictionary at fit
time.
Reference Issues/PRs
Fixes #26482
What does this implement/fix? Explain your changes.
This PR runs
SparseCoder
common tests by acceptingdictionary
asrequired_parameters
inutils.estimator_cheks._construct_instance
.SparseCoder
instance inutils.estimator_cheks._construct_instance
functionSparseCoder
SparseCoder
SparseCoder.transform()
which was failing during common testsn_features_in
of inputX
should matchn_features
ofprecomputed_dictionary
ofSparseCoder
get_features_out
tests were skipped for SparseCoder due to SparseCoder'sfeature_names_in
attribute not resetting based on input.Any other comments?