One split is a single noisy measurement
A held-out test set gives one number, computed on one arbitrary slice of the data.
- : the model's true error rate.
- : the size of the test set.
A model with a true error of 10 percent, measured on 200 rows, has a standard error of about 2 points.
So two models that differ by a point on such a split are not distinguishable, and the split itself decided which one looked better.
What k-fold averages away
- : the number of folds.
- : the error on fold , measured by a model trained on the other .
Every row is used for validation exactly once and for training times, so the estimate uses all the data and the model still never scores itself.
Five or ten is the standard choice, and it is a compromise: higher trains on more data so bias falls, but the folds overlap more so the average is less stable.
One run, in order
- Shuffle the rows, unless they are ordered in time.
- Cut them into folds of equal size.
- For each fold, train on the other and score the held-out one.
- Average the scores, and report their spread alongside.
- Retrain on all the data for the model you actually ship.
The variants that exist for a reason
Stratified k-fold keeps each class at the same proportion in every fold, which matters as soon as one class is rare enough that a fold could miss it.
Group k-fold keeps all rows sharing an identifier in the same fold, so a patient or a user cannot appear in training and validation at once.
Time series cross-validation never shuffles. Each fold trains on the past and validates on the future, because a shuffled split lets the model see tomorrow.
Leave-one-out is k-fold taken to its limit: almost unbiased, expensive, and high variance because the training sets are nearly identical.
The mistake that quietly inflates every number
Any step fitted on the data belongs inside the loop, not before it.
Scaling, imputation, feature selection and target encoding all learn from the rows they see, so fitting them on the full dataset leaks the validation folds into training.
Selecting the best of 200 hyperparameter settings by cross-validation also makes that score optimistic, because the choice was made using it.
A second, outer split is the only honest way to report what such a model scores on data nothing has touched.