Cross-validation (CV) rotates train/validation folds so performance estimates are less dependent on one lucky split—especially when data are limited.
k-fold idea
Split data into k parts (folds). Train on k−1 folds, validate on the held-out fold. Repeat k times and average metrics.
Stratified k-fold
Preserves class proportions in each fold—default for imbalanced classification.
Time series CV
Use rolling or expanding windows—never shuffle future into past for forecasting.
What CV does not replace
- Still need a final held-out test set or fresh production monitoring
- Hyperparameter tuning inside CV must not peek at test set
sklearn cross_val_score automates this locally after you understand the loop.
Important interview questions and answers
- Q: Why k-fold?
A: More stable performance estimate than single split when data size is modest. - Q: Nested CV?
A: Outer loop estimates performance; inner loop tunes hyperparameters—reduces optimistic bias.
Self-check
- Describe k-fold cross-validation.
- Why stratify folds for classification?
- Why not shuffle time series for CV?
Tip: CV reduces overfitting to one lucky split.
Interview prep
- k-fold?
Multiple train/val splits average performance estimate.