Step by Step
R
Regular K-fold — splits data randomly, no ratio guarantee
Regular K-fold splits data into folds purely randomly, with no guarantee that each fold's class proportions will match the overall dataset's class proportions.
Example: with a 5% positive class, one random fold might happen to contain 0% positives by pure chance, while another might contain 15%.
S
Stratified K-fold — preserves class proportions in every fold
Stratified K-fold specifically ensures each fold maintains the same class proportions as the full dataset, preventing the wildly variable, unreliable scores that regular K-fold can produce on imbalanced data.
Example: with a 5% positive class overall, stratified K-fold ensures every single fold also contains approximately 5% positive examples.
⚡
The rule — always stratify for classification
For classification tasks, especially with class imbalance, always use stratified K-fold rather than regular K-fold. For regression tasks (where there's no discrete class to preserve ratios of), regular K-fold is fine.
Example: using StratifiedKFold for a fraud classification model, but regular KFold for a house price regression model.
Applied Walkthrough
1
A classification model is evaluated using regular (non-stratified) K-fold on a dataset where only 5% of examples belong to the positive class.
2
By pure chance, one of the folds ends up with 0% positive examples, while another ends up with 15% positive examples.
3
This wildly uneven distribution across folds produces unreliable, highly variable performance scores from fold to fold, none of which fairly represents the model's true expected performance.
4
Switching to stratified K-fold instead ensures every single fold maintains roughly the same 5% positive class proportion as the overall dataset, producing far more reliable and consistent performance estimates across folds.
Exam Application
Exams test whether you know the simple rule: use StratifiedKFold for classification tasks (especially imbalanced ones), and regular KFold for regression tasks. Also expect a scenario-based question asking you to identify why regular K-fold produced unreliable results on an imbalanced classification dataset.
⚠ Common Trap
The most common trap is using regular K-fold by default for a classification task without considering class imbalance. On any meaningfully imbalanced classification dataset, regular K-fold risks producing folds with wildly different class proportions purely by chance, leading to unreliable performance estimates.
✓ Quick Self-Check
1. What is the key difference between regular K-fold and stratified K-fold?
Stratified K-fold ensures each fold maintains the same class proportions as the full dataset; regular K-fold splits purely randomly with no such guarantee.
Tap to reveal / hide
2. What problem can occur with regular K-fold on an imbalanced classification dataset?
Some folds might end up with wildly different class proportions (like 0% or 15% positive) purely by chance, producing unreliable, highly variable performance scores.
Tap to reveal / hide
3. When should you use stratified K-fold?
For classification tasks, especially with class imbalance.
Tap to reveal / hide
4. When is regular K-fold considered fine to use?
For regression tasks, where there's no discrete class ratio to preserve.
Tap to reveal / hide
5. What is the simple rule of thumb for choosing between the two?
If you are classifying, use StratifiedKFold; for regression, regular KFold is fine.
Tap to reveal / hide