What is cross-validation, and why is k-fold preferred over a single train/test split?
Classic MLLevel: FoundationClassical machine learning
What is cross-validation, and why is k-fold preferred over a single train/test split?
Hints
- Which observations must remain independent during evaluation?
- Compare random, grouped and temporal splits. Where are hyperparameters selected?
Answer
Cross-validation splits data into k folds, training on k−1 folds and validating on the remaining fold, rotating through all k combinations and averaging the results. This gives a more robust estimate of generalization performance than a single split, because it reduces the variance introduced by an unlucky/lucky split, and every data point gets used for both training and validation. Stratified k-fold is preferred for classification with imbalanced classes; time-series/rolling-window CV is required when data has temporal structure (to avoid leakage from the future).
Source and licence: Ishan Dutta — Awesome Data Science Interview Q&A · MIT