Cross-Validation
Cross-validation is a resampling technique that estimates how a model will generalize to unseen data by reusing what is available. Its flagship method, k-fold, is used to compare models, tune hyperparameters and detect overfitting.
Cross-validation is a resampling technique that estimates how well a model will generalize to data it has never seen, while making efficient use of the data on hand. Instead of setting aside a single block for testing, it splits the data several times and averages the outcomes, so that every observation ends up serving both to train and to validate.
Its worth lies in producing an error estimate that is less noisy and less dependent on the luck of a single split than one lone train/test partition. The modern formulation is credited to Stone (1974), and it has since become a central tool for gauging a model's predictive ability without the self-deception of judging it on the very data it was fitted on.
K-fold validation and its variants
The flagship method is k-fold cross-validation. The data is split into k blocks of similar size; the model trains on k−1 of them and validates on the one left out, and the process repeats k times, rotating which block is held out. The k estimates are then averaged. Common values of k are 5 or 10: Kohavi's classic 1995 study recommended stratified ten-fold cross-validation for real-world datasets as a sound trade-off between bias and variance.
Several variants matter. In leave-one-out (LOO), k equals the number of observations: the model is validated one example at a time, which squeezes the most out of the data but is costly and high-variance. Stratified cross-validation keeps each fold with the same class proportions as the full set, which matters when there are minority classes or imbalanced data.
What it is for: model and hyperparameter selection
Cross-validation underpins comparing models, tuning hyperparameters and detecting overfitting. By yielding a steadier performance estimate, it lets you choose between algorithms or settings without being misled by a fortunate split. In practice it pairs with hyperparameter search: for each configuration the cross-validated error is computed and the best one is kept. When an honest estimate of final performance is also needed, nested cross-validation separates the tuning step from the evaluation step so that one does not contaminate the other.
Pitfalls to avoid: data leakage and time series
The most common mistake is data leakage: any preprocessing —scaling, imputation, feature selection— fitted on all the data before splitting contaminates the validation, because the test fold is no longer genuinely unseen. The rule, stressed in Hastie, Tibshirani and Friedman's The Elements of Statistical Learning and in the scikit-learn documentation, is to fit every preprocessing step inside each fold, ideally by chaining it into a pipeline.
The other tricky case is time series: shuffling the observations breaks their order and lets a model «predict the past from the future», invalidating the estimate. Here one uses time-aware schemes that always train on the past and validate on the future; Bergmeir and Benítez (2012) examined this question in depth. The specifics of temporal handling are covered in the time-series entry.
Pieces using this term
This article was produced with artificial intelligence under human editorial oversight.