Skip to content

Change default high cardinality encoder to StringEncoder - #1354

Merged
Vincent-Maladiere merged 14 commits into
skrub-data:mainfrom
rcap107:deprecate-gap-default
May 12, 2025
Merged

Vincent-Maladiere merged 14 commits into
skrub-data:mainfrom
rcap107:deprecate-gap-default

Conversation

@rcap107

@rcap107 rcap107 commented Apr 30, 2025

Copy link
Copy Markdown
Member

This is a draft PR for changing the default encoders from Gap (in the TableVectorizer) and Minhash (in the tabular_learner) to StringEncoder in both cases.

@rcap107

rcap107 commented Apr 30, 2025

Copy link
Copy Markdown
Member Author

Two tests are failing and I am not sure what's the best way to address the issues

When testing the tabular_learner, test_linear_learner is expecting a GapEncoder as default parameter, but the default parameter is now "warn", so the assert fails

I tried to address the TableVectorizer test by adding a filterwarning, but I managed to turn that into an internal error of pytest by doing that

@rcap107
rcap107 marked this pull request as ready for review April 30, 2025 12:44
@jeromedockes

Copy link
Copy Markdown
Member

@glemaitre talking with @rcap107 we were thinking the simplest thing here would be to warn in __init__ if the given high_cardinality is HIGH_CARDINALITY_TRANSFORMER. But I guess in scikit-theory we should not warn in init but in fit. however that means having a less informative attribute like "warn" . WDYT?

@glemaitre

Copy link
Copy Markdown
Member

I have a high bias towards what scikit-learn do. However, I'm not sure that our encoders are passing the test suite so maybe we could avoid it.

@glemaitre

Copy link
Copy Markdown
Member

Also I see that you are using a DeprecationWarning. In scikit-learn, we would use a FutureWarning instead. DeprecationWarning are usually silenced by default and more intended to developers.

@jeromedockes

Copy link
Copy Markdown
Member

what scikit-learn do.

in this case (change the default value of an argument) what is the "canonical" approach?

@glemaitre

Copy link
Copy Markdown
Member

Indeed, we use the "warn" string in __init__ and check in fit.

We document it here: https://scikit-learn.org/dev/developers/contributing.html#change-the-default-value-of-a-parameter

@jeromedockes

Copy link
Copy Markdown
Member

Indeed, we use the "warn" string in init and check in fit.

ok but then the attribute is "warn" so we cannot set params on the subestimator if we use the default right. which is why the current defaults are what they are and we clone in the init -- I don't know if you remember that discussion from way back

@jeromedockes jeromedockes added this to the 0.6.0 milestone Apr 30, 2025
@jeromedockes jeromedockes changed the title Changing default high cardinality encoder to StringEncoder FutureWarning about Changing default high cardinality encoder to StringEncoder Apr 30, 2025
@GaelVaroquaux

GaelVaroquaux commented Apr 30, 2025 via email

Copy link
Copy Markdown
Member

@glemaitre

Copy link
Copy Markdown
Member

Yep. I'm fine to be pragmatic and have something working.

@rcap107

rcap107 commented May 1, 2025

Copy link
Copy Markdown
Member Author

In this case, which one is the "pragmatic approach"?

@jeromedockes

Copy link
Copy Markdown
Member

In this case, which one is the "pragmatic approach"?

I think issuing the warning in _clone_if_default and keeping everything else the same

@rcap107

rcap107 commented May 6, 2025

Copy link
Copy Markdown
Member Author

should the deprecation be more evident in the changelog?

Comment thread pyproject.toml Outdated
Comment on lines +291 to +292
# TODO: remove when StringEncoder is set as default high cardinality encoder
'ignore:.*default high_cardinality encoder*:FutureWarning',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can remove this?

@jeromedockes

Copy link
Copy Markdown
Member

should the deprecation be more evident in the changelog?

I think so, maybe by putting it at the top of the changes section and maybe even using a

.. warning::

   high cardinality changed...

directive?

also in the docstring itself, at the end of the paragraph about this encoder, you can use a directive similar to:

        .. versionchanged:: 0.22
            ``cv`` default value if None changed from 3-fold to 5-fold.

(search for "versionchanged" in the scikit-learn codebase and you will find many examples)

@jeromedockes jeromedockes changed the title FutureWarning about Changing default high cardinality encoder to StringEncoder Change default high cardinality encoder to StringEncoder May 6, 2025

@jeromedockes jeromedockes left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks a lot @rcap107 ! this will speed-up a lot of pipelines that use the tablevectorizer :)

@Vincent-Maladiere Vincent-Maladiere left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @rcap107

@Vincent-Maladiere
Vincent-Maladiere merged commit 9615f7f into skrub-data:main May 12, 2025
@rcap107
rcap107 deleted the deprecate-gap-default branch September 4, 2026 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants