Level 2 · Module 11 · 10 minutes
Cross-validation: taking turns as the test set
- Explain how cross-validation takes turns holding out each part of the data.
- Explain why averaging over folds gives a steadier estimate on small data.
- Describe variations for classes, groups and time, and the extra cost of the method.
Cross-validation tests a model several times by splitting the data into parts and taking turns holding one part out. Each round trains on the remaining parts and measures the model on the part left out. The scores are then averaged, giving a steadier result than a single lucky or unlucky split.
The idea in plain words
Divide the rows into several equal groups, often called folds. Train on all folds except one, test on the fold held out, then rotate which fold is held out. Every row is used for training in most rounds and tested exactly once. The average across rounds estimates how the model behaves on unseen rows, with less dependence on one particular split.
Why averages help
With a small table, one split can produce a misleading score by chance. A validation pile of a few dozen rows might contain an unusual run of cases. Averaging over several rotations smooths those accidents. The spread between rounds is also useful: a large spread means the result is fragile and should be treated with caution.
Variations that respect the problem
- Stratified folds keep the mixture of classes similar in every fold, so a rare class is not missing from some rounds.
- Grouped folds keep rows from the same person, shop or order in one fold, preventing recognition in place of learning.
- Time-ordered folds always train on the past and test on the future, matching real use.
These choices matter more than the number of folds. A cross-validation that mixes the future into training gives a confident but wrong answer.
The costs and the honest finale
Cross-validation trains the model several times, so it takes longer. On very large datasets a single well-made split is often enough. It is most useful when data is limited and every row must count. The final chosen model still deserves an untouched test pile for a single honest estimate, and the process of choosing settings must not consult that pile.
Practice versus real training
Rotating written cards between a training pile and a held-out pile is a simplified teaching picture. Real software fits and scores each fold automatically, and commercial teams use the method when a single split would be too fragile to trust. No model is trained in this lesson; the rotation is done on paper.
Common misconception
Cross-validation means the model is trained once and then checked many times. Each round trains a fresh model on the other folds and tests it on the held-out fold. That is why cross-validation costs several training runs. It is a series of honest trials, not repeated scoring of one model.
Guided practice
Write the names of several hypothetical shops on cards. On paper, sort the cards into four folds using two different rules: once keeping all rows from the same town together, once ignoring towns. For each rule, describe one round in which the held-out fold is used for testing. Then write which rule you would trust and why. No model is trained; the folds are made on paper only.
Knowledge check
Independent practice
Write a short example from your own work or daily life and decide whether it is AI, ordinary software or a mixture. Then explain why. Save it in your notes; no account is required.
Last reviewed: · Report a problem