scikit-learn / scikit-learn/scikit-learn
Add RepeatedStratifiedGroupKFold
Open
Nobody has claimed this yet.
module:model_selection
New Feature
- Dominant language
- Python
- Stars
- 67.3k
- Forks
- 27.4k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 58
Description
Describe the workflow you want to enable
Building off conversation #13621 and work already done in #18649, I'd like to add an implementation of RepeatedStratifiedGroupKFold.
Describe your proposed solution
See the implementation in #24227. Then RepeatedStratifiedGroupKFold could be used similar to below:
>>> import numpy as np
>>> from sklearn.model_selection import RepeatedStratifiedGroupKFold
>>> X = np.random.randn(10, 1)
>>> y = np.array([0, 0, 0, 0, 0, 1, 1, 1, 1, 1])
>>> groups = np.array([1, 1, 2, 2, 2, 3, 4, 4, 5, 5])
>>> rsgkf = RepeatedStratifiedGroupKFold(n_splits=3, n_repeats=2, random_state=42)
>>> for train_idxs, test_idxs in rsgkf.split(X, y, groups):
... # print the group assignment for the train/test indices
... print("TRAIN:", groups[train_idxs], "TEST:", groups[test_idxs])
... X_train, X_test = X[train_idxs], X[test_idxs]
... y_train, y_test = y[train_idxs], y[test_idxs]
TRAIN: [2 2 2 4 4 5 5] TEST: [1 1 3]
TRAIN: [1 1 3 4 4 5 5] TEST: [2 2 2]
TRAIN: [1 1 2 2 2 3] TEST: [4 4 5 5]
TRAIN: [1 1 4 4 5 5] TEST: [2 2 2 3]
TRAIN: [2 2 2 3 4 4 5 5] TEST: [1 1]
TRAIN: [1 1 2 2 2 3] TEST: [4 4 5 5]
Describe alternatives you've considered, if relevant
No response
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the proposed implementation in issue #24227 and the related discussions in #13621 and #18649. Check how RepeatedStratifiedGroupKFold should expose split(X, y, groups) with n_splits, n_repeats, and random_state, and consider the supplied example output as the completion behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100