When should stratified sampling be used?
Stratified sampling should be used when important groups in the dataset need to be represented in similar proportions across the resulting samples or data splits.
It is especially useful in classification problems where some classes are much more common than others.
Use it when classes are imbalanced
Suppose a fraud dataset contains:
- 98% legitimate transactions
- 2% fraudulent transactions
A simple random split might accidentally place too few fraud examples in the validation or test set.
Stratified sampling helps preserve approximately the same 98/2 class distribution in each split.
Use it when the dataset is relatively small
With smaller datasets, random variation can easily create uneven class distributions.
Stratification helps ensure that each subset contains enough examples from important classes to support meaningful training and evaluation.
Use it when evaluation depends on class representation
Stratification is useful when model performance needs to be measured fairly across all target classes.
If one evaluation split contains very few examples of a minority class, metrics such as precision, recall, or F1 score can become unstable or misleading.
When stratified sampling may not be the right choice
Stratification should not override more important structure in the data.
For example:
- Time-dependent data: preserve chronological order instead of randomly stratifying future and past records.
- Grouped data: keep related records from the same customer, patient, device, or account in the same split when needed.
- Very rare classes: stratification can preserve proportions, but it cannot create enough examples if the original dataset contains too few.
What should usually be stratified?
In supervised classification, the target label is most commonly used for stratification.
For example, if the target contains spam and not spam, the split can preserve the proportion of those two classes.
In short, use stratified sampling when maintaining the representation of important classes or groups is necessary for reliable training and evaluation, particularly with imbalanced or smaller classification datasets.
Learning Sequence
Machine Learning Curriculum
Explore Related Questions
Deepen your understanding across related Machine Learning topics.