Cross-validation provides honest estimates of model performance on unseen data.
K-Fold CV:
- Split data into equal folds (typically or )
- For each fold : train on all folds except , evaluate on fold
- Average performance across all evaluations
Why not just train/test split?
- Single split is high variance — performance depends on which data ended up in test
- K-fold uses all data for both training and evaluation
- Gives mean and standard deviation of performance
Variants:
- Stratified K-fold — preserves class distribution in each fold (use for imbalanced data)
- Leave-one-out (LOO) — , most expensive but lowest bias
- Repeated K-fold — run K-fold multiple times with different random splits
Use cases:
- Model selection — compare models (e.g., different hyperparameters) by their CV score
- Hyperparameter tuning — grid/random search over hyperparameters, using CV to evaluate each
- Final evaluation — estimate generalization error of the chosen model
Pitfall: never tune hyperparameters on the test set. Use nested CV or a separate validation set for tuning, then evaluate once on test.
See also: Bias-Variance Tradeoff, Evaluation Metrics