Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Shreesha3112
Copy link
Contributor

@Shreesha3112 Shreesha3112 commented Jun 24, 2023

Reference Issues/PRs

Fixes #26482

What does this implement/fix? Explain your changes.

This PR runs SparseCoder common tests by accepting dictionary asrequired_parameters in utils.estimator_cheks._construct_instance.

  • Constructs SparseCoder instance in utils.estimator_cheks._construct_instance function
  • Adds parameter validation for SparseCoder
  • Adds stateless tag for SparseCoder
  • Fixes data type preservation for SparseCoder.transform() which was failing during common tests
  • Test modifications were needed as as n_features_in of input X should match n_features of precomputed_dictionary of SparseCoder
  • Some get_features_out tests were skipped for SparseCoder due to SparseCoder's feature_names_in attribute not resetting based on input.

Any other comments?

@github-actions
Copy link

github-actions bot commented Jun 24, 2023

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: eebf61a. Link to the linter CI: here

@Shreesha3112 Shreesha3112 changed the title Enh/run common tests sparse coder ENH/run common tests sparse coder Jun 25, 2023
@Shreesha3112 Shreesha3112 changed the title ENH/run common tests sparse coder ENH run common tests for SparseCoder Jun 25, 2023
@Shreesha3112 Shreesha3112 force-pushed the ENH/run-common-tests-SparseCoder branch from 4d8db48 to 3b8e328 Compare June 25, 2023 10:02
@Shreesha3112 Shreesha3112 marked this pull request as ready for review June 25, 2023 11:21
@glemaitre glemaitre self-requested a review November 3, 2023 18:40
:mod:`sklearn.decomposition`
............................

- |Fix| :meth:`decomposition.SparseCoder.transform` now preserves data
Copy link
Member

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
Copy link
Member

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):
Copy link
Member

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"],):
Copy link
Member

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":
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Run common test for SparseCoder and FeatureUnion
2 participants