CLASSIFICATION · BEGINNER GUIDE
Stratified Cross-Validation for Classification
Keep class proportions more balanced across folds while preserving independent groups and avoiding leakage.
Quick answer: Stratified cross-validation aims to preserve class proportions in each fold. This can make fold scores more comparable when classes are imbalanced, but it does not replace grouping or time-aware splits when observations are dependent.
What this method answers
If a rare class has only a few cases, ordinary folds may omit it from validation or training. Stratification distributes available labels across folds, while grouped validation keeps related entities together.
Use stratification for independent labelled cases when class balance matters. For repeated people, sites or time series, prioritize the dependence structure and choose a split that reflects future use.
Before running a calculation, write down the population and the exact quantity you want to estimate. A method name alone does not define the question, the comparison or the assumptions.
Steps to follow
- Count labels and identify related or repeated observations.
- Choose the split based on deployment and independence, not just class balance.
- Apply stratification only if it does not violate group or time constraints.
- Report fold design and minority-class counts alongside performance.
Keep a record of exclusions, recoding decisions and software settings. That makes the analysis easier to check and repeat.
Worked example
A dataset has 100 rows: 90 negative and 10 positive. Five-fold stratification aims for about 18 negative and 2 positive cases in each validation fold.
| Per validation fold | Approximate count |
|---|---|
| Negative | 18 |
| Positive | 2 |
| Total | 20 |
Across five folds, each positive case is evaluated once. With only two positives per fold, metrics such as recall can still vary sharply; stratification cannot create more positive information.
Interpret the result carefully
Stratified scores may be more stable than folds with zero positives, but uncertainty remains high when the minority class is small.
Limit to keep in mind: Stratified splitting can leak information if duplicate or related records cross folds, or if a time series is randomly partitioned. It preserves labels, not independence.
When reporting an analysis, include the sample size, estimate, units and uncertainty. Explain why the method fits the sampling and measurement design. Separate planned tests from exploratory checks, and avoid saying that association proves a cause.
Frequently asked questions
Does stratification balance every fold exactly?
Not always; counts are allocated as evenly as possible given sample size and constraints.
Can I use it with grouped records?
Use a group-aware method so records from the same entity do not cross train and validation folds.
Does it fix a very small minority class?
No. It distributes the few cases but cannot increase the information available.
Can I stratify time-series data?
Random stratification can break time order; use temporal validation when future prediction is the goal.