Grouped cross-validation
Grouped cross-validation evaluates a predictor using splits that keep all observations from each specified group together in either training or testing within a split.
Grouped data breaks the i.i.d. assumption when samples share a source, such as several samples from each patient. GroupKFold keeps a group out of training whenever it is in a test fold, and its test folds form a complete partition of the data. [2] Its default is 5 folds, at least 2 are required and the number of distinct groups must be at least the number of folds. [1]
Grouping by physical drive tests unseen drives and grouping by site tests unseen sites, which are different generalization questions. StratifiedGroupKFold also tries to keep class proportions, LeaveOneGroupOut holds out one group per split and GroupShuffleSplit draws independent random group splits. [2]
Kapoor and Narayanan list non-independence between training and test samples as a leakage type, for example different observations of the same patient on both sides of the split. Their survey found leakage-related errors reported in 17 fields, affecting 329 papers. [3]
Relations
Advantages
- Estimates performance on groups absent from training, which a sample-level split overstates when samples within a group are dependent. [3, 2]
Limitations
- Choose groups for the deployment question. Grouping does not prevent future information or globally fitted preprocessing from entering training. [2]
- Fold sizes can differ when groups are unequal, because shuffled GroupKFold balances the number of groups rather than samples. [2]
Citations
- scikit-learn: GroupKFold, non-overlapping groups and per-fold behavior.
- scikit-learn: cross-validation for grouped data, time series and training-only transformations.
- Sayash Kapoor and Arvind Narayanan. Leakage and the Reproducibility Crisis in ML-based Science. arXiv:2207.07048v1, 2022.
Sources & caveats
- sklearn-validation is the scikit-learn user guide on cross-validation, re-read on 2026-10-22 in the section on grouped data.
- sklearn-groupkfold is the scikit-learn GroupKFold API page, re-read on 2026-10-22, and is the source of the 5 and 2 fold values.
- leakage is the 2022 arXiv preprint by Kapoor and Narayanan of Princeton University, read on 2026-10-22 in the abstract and leakage taxonomy.
- The 17 fields and 329 papers come from leakage.