8000 ENH Adds warning & docs for splitters that do not support goups by thomasjpfan · Pull Request #28210 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

ENH Adds warning & docs for splitters that do not support goups #28210

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

Merged
merged 7 commits into from
Jan 26, 2024

Conversation

thomasjpfan
Copy link
Member
@thomasjpfan thomasjpfan commented Jan 21, 2024

Reference Issues/PRs

Closes #22848

What does this implement/fix? Explain your changes.

This PR:

  • Adds private _UnsupportedGroupCVMixin mixin that updates the docstrings of CV splitters that do not support groups. It also includes a warning if groups are passed in.
  • For CV splitters, that define their own split method, this PR adds a warning there. For PredefinedSplitter and TimeSeriesSplitter, it raises a warning during split when the generator is created.

Any other comments?

Implementation wise, I moved ShuffleSplit._iter_indices to BaseShuffleSplit._iter_indicies, so that GroupShuffleSplit can directly inherit from BaseShuffleSplit. This way GroupShuffleSplit is not inheriting from a splitter that does not support groups.

Copy link
github-actions bot commented Jan 21, 2024

✔️ Linting Passed

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

Generated for commit: 5a364b2. Link to the linter CI: here

@@ -96,6 +96,10 @@
)
digits = load_digits()

pytestmark = pytest.mark.filterwarnings(
Copy link
Member

Choose a reason for hiding this comment

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

It is a bit weird for me to have this filter globally set for the file.

We should have our test catching the warning to make sure that we raise it when we expect or otherwise, we should raise an error.

Is there a particular reason to go fine grain here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I converted this pytestmark to error instead and updated the tests.

@@ -1698,7 +1761,31 @@ def __init__(self, *, n_splits=5, n_repeats=10, random_state=None):


class BaseShuffleSplit(_MetadataRequester, metaclass=ABCMeta):
"""Base class for ShuffleSplit and StratifiedShuffleSplit."""
"""Base class for ShuffleSplit and StratifiedShuffleSplit.
Copy link
Member

Choose a reason for hiding this comment

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

and the GroupShuffleSplit as well. Maybe "*ShuffleSplit is enough.

@glemaitre glemaitre self-requested a review January 22, 2024 11:10
Copy link
Member
@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

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

I think it makes sense. I was actually not aware of the predefined splitter. I think that we don't document it in our API documentation.

I'll open a PR.

We do have it documented.

Copy link
Member
@adrinjalali adrinjalali left a comment

Choose a reason for hiding this comment

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

I have a secret plan to make all splitters support group and strata (#26821) to all splitters and to simply the interface a bit.

But in the meantime this is a nice fix.

Copy link
Member
@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @thomasjpfan

@glemaitre glemaitre merged commit 1106c91 into scikit-learn:main Jan 26, 2024
glemaitre pushed a commit to glemaitre/scikit-learn that referenced this pull request Feb 10, 2024
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.

KFold splitter falsely claims it supports groups
4 participants
0