Understand the idea
The most reliable way to know how a model will do on data it has never seen is to actually try it on data it has never seen. Cross-validation does this systematically: split the data into several chunks (folds), fit the model on all chunks but one, test it on the chunk that was left out, and repeat until every chunk has had a turn being the test set.
K-fold cross-validation with k = 5 or k = 10 is the common default: the data is split into 5 or 10 roughly equal folds, and the model is fit and tested 5 or 10 times, each time leaving out a different fold. The final reported score is the average across all folds, which uses every row for both fitting and testing without ever testing on data the model was trained on.
This matters because a model's score on the SAME data it was fit to is almost always optimistic: cross-validation is the standard defense against being fooled by that optimism, and against choosing a model that merely memorized its training sample.
Cross-validation is often shortened to CV. The simplest form of this idea is a train-test split: fit the model on one part of the data and score it on the held-out rest. Leave-one-out cross-validation is the extreme case where each fold holds a single row, so the model is refitted once per row. The one-standard-error rule picks the simplest model whose cross-validated score is within one standard error of the best score, trading a tiny loss in accuracy for a simpler model.
Practitioner explanation
K-fold CV trades bias and variance in the performance ESTIMATE itself: small k (e.g. 2) gives a pessimistically biased estimate (each fit sees less data than the full sample) but low variance across folds; large k (up to leave-one-out, k = n) reduces that bias but increases variance and computational cost, and for highly flexible models LOOCV can actually have HIGHER variance than moderate k due to the near-identical, highly correlated training sets across folds.
Stratified k-fold (preserving the outcome's class balance within each fold) is essential for classification with imbalanced classes; for time series, ordinary random-fold CV leaks future information into training folds and must be replaced by a forward-chaining (rolling-origin) split instead. Nested CV is required when the SAME cross-validation is also used to tune hyperparameters, otherwise the reported performance is optimistically biased by having selected the best-looking configuration on the same folds used to report its score.
KernelStats' Cross-Validated Model Comparison reports the per-fold scores, their standard error, and applies the one-standard-error rule across a candidate set of models (OLS, ridge, lasso and KNN for regression; ridge classifier, logistic and KNN for classification, with stratified folds) so that a model is not selected merely for beating another by an amount smaller than the estimate's own noise. It has no time-aware or grouped split: time-ordered data belongs in Forecast Backtest (Rolling-Origin), which uses rolling-origin splits.
When to use it
Consider it when
Whenever a model's real-world predictive performance needs to be estimated, or when choosing between competing models or hyperparameter settings.
Use caution when
Do not use ordinary random k-fold splits on time-ordered data, where a forward-chaining split is required to avoid training on future information; and do not reuse the same CV folds both to tune a model and to report its final performance without nesting.
Formulas and symbols
K-fold cross-validated metric
The average of the chosen metric (R-squared, accuracy, RMSE) across the k held-out folds.
Common misconceptions
Misconception
Cross-validation and a single train/test split give equally reliable performance estimates.
Correction
A single split's estimate depends heavily on which rows happened to land in the test set, especially at moderate n. Cross-validation averages over several such splits, producing a less noisy estimate and, importantly, a standard error across folds that a single split cannot provide.
References
- NIST/SEMATECH e-Handbook of Statistical Methods, §4.4.3.7 Model validation, NIST/SEMATECH (2012), §4.4.3.7.
