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

Skip to content

MNT: mark FeatureHasher and HashingVectorizer with requires_fit=False… #31557

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 1 commit into
base: main
Choose a base branch
from

Conversation

rrricharrrd
Copy link
Contributor

Reference Issues/PRs

Closes #30689

What does this implement/fix? Explain your changes.

Adds requires_fit=False tag to these classes

Any other comments?

N/A

@betatim @glemaitre

Copy link

✔️ Linting Passed

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

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

@glemaitre glemaitre self-requested a review June 16, 2025 17:44
@betatim
Copy link
Member

betatim commented Jun 16, 2025

Thanks for helping clean this up! Looks good to me.

Let's see what the testing robots have to say.

@adrinjalali could you explain in a bit more detail what you meant with "require_fit=False can be tricky if there is validation"? HashingVectorizer does some work in its fit.

@glemaitre
Copy link
Member

So because those estimators do not accept normal NumPy array (they are vectorizer) they are not covered by the common test (tests run in test_common.py and defined in estimator_checks.py).

We therefore need non-regression tests for the FeatureHasher and HashingVectorizer in the file test_feature_hasher.py and test_text.py. The test should check that we can call transform method without calling the fit method and that it does not raise any error.

@adrinjalali
Copy link
Member

@adrinjalali could you explain in a bit more detail what you meant with "require_fit=False can be tricky if there is validation"? HashingVectorizer does some work in its fit.

As in, do we expect the transformer to do any kind of feature count / feature name consistency between fit and transform? An estimator might technically not require fit to run transform, but we might expect the transform to do those basic validations. I just meant to make sure that expectation is not there when we set the tags.

@glemaitre
Copy link
Member

As far that I recall, we defined stateless as: if you call fit you get some validation for free but you can call transform and go on but without those validation.

@thomasjpfan
Copy link
Member

if you call fit you get some validation for free but you can call transform and go on but without those validation.

Time to update the glossary entry?

stateless
An estimator is stateless if it does not store any information that is
obtained during :term:`fit`. This information can be either parameters
learned during :term:`fit` or statistics computed from the
training data. An estimator is stateless if it has no :term:`attributes`
apart from ones set in `__init__`. Calling :term:`fit` for these
estimators will only validate the public :term:`attributes` passed
in `__init__`.

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.

FeatureHasher and HashingVectorizer does not expose requires_fit=False tag
5 participants