Skip to content

FIX binary y in sample weight equivalence check#30775

Merged
jeremiedbb merged 6 commits into
scikit-learn:mainfrom
antoinebaker:enforce_y_tags_sample_weight
Feb 10, 2025
Merged

FIX binary y in sample weight equivalence check#30775
jeremiedbb merged 6 commits into
scikit-learn:mainfrom
antoinebaker:enforce_y_tags_sample_weight

Conversation

@antoinebaker

@antoinebaker antoinebaker commented Feb 6, 2025

Copy link
Copy Markdown
Contributor

Reference Issues/PRs

Fixes #30770. Thanks a lot @pierrenodet for the bug report!

What does this implement/fix? Explain your changes.

The _enforce_estimator_tags_y allows to convert a generic y to a binary one for estimators that require it (binary classifiers). Unfortunately the current method (taking the first element as the negative class) is sensitive to shuffling and _check_sample_weight_equivalence converts y after shuffling, which makes the _check_sample_weight_equivalence wrongly fail on binary classifiers.

This PR takes y.min() as the negative class to make _enforce_estimator_tags_y insensitive to shuffling.

@antoinebaker antoinebaker changed the title Enforce y tags sample weight FIX binary y in sample weight equivalence check Feb 6, 2025
@github-actions

github-actions Bot commented Feb 6, 2025

Copy link
Copy Markdown

✔️ Linting Passed

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

Generated for commit: 6a05009. Link to the linter CI: here

@antoinebaker antoinebaker marked this pull request as ready for review February 7, 2025 10:40

@ogrisel ogrisel 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.

Thanks, @antoinebaker. Can you please add a fix changelog entry? Other than that, LGTM.

@jeremiedbb jeremiedbb 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. Just 1 question below

Comment thread sklearn/utils/estimator_checks.py
@jeremiedbb jeremiedbb added this to the 1.6.2 milestone Feb 7, 2025
@@ -0,0 +1,7 @@
- :func:`utils.estimator_checks._enforce_estimator_tags_y` enforces a binary `y`

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.

Let's not reference the private API in the changelog. We just need to mention that the 2 checks have been for binary targets.

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.

Issue with binary classifiers in _check_sample_weight_equivalence?

3 participants