A model scores well on one validation split and poorly on the next. Which result should you trust? Cross-validation helps you see how much the score depends on which examples the model trains on and which ones it has to predict.
Cross-validation evaluates a model across several train-and-validation splits. You fit a fresh model for each split, score it on the held-out portion, and summarize the results. The most important choice is what to hold out. If the model will see new devices, hold out whole devices. If it will predict future demand, hold out later dates.
Pick the split that matches how the model will be used
| What will the model see? | Split to consider | What to protect |
|---|---|---|
| New independent examples | K-fold | Keep each validation fold separate from its training examples. |
| New independent examples with uneven class counts | Stratified K-fold | Keep class proportions roughly similar across folds when feasible. |
| New users, devices, or other groups | Group K-fold | Keep a group entirely on one side of the split. |
| Future observations | Forward or time-series split | Train on earlier records and validate on later ones. |
Start with the unit that must be new in production. A row may be an independent purchase on one project and one of hundreds of readings from the same device on another. The row count alone cannot tell you which split is appropriate. Scikit-learn cross-validation guide.
Walk through five folds with 100 examples
Suppose you have 100 independent labeled examples. Divide them into five folds of 20. In round one, train on folds two through five and validate on fold one. In round two, hold out fold two and train on the other four. Repeat until each fold has served as validation once.

Each round fits a fresh copy of the training procedure. Each example contributes to validation once and can contribute to training in other rounds. This gives five scores whose average describes the performance observed across these splits.
For example, validation accuracies of 85%, 80%, 90%, 75%, and 85% average to 83%. Report the individual scores or their spread as well. In this case, the 15-point span suggests that the average alone would hide variation between folds. Fold scores share training data, so their spread is descriptive and should not automatically be turned into a confidence interval.
Three situations that change the split
Rare classes need enough examples to score
Stratification helps distribute a rare class across folds for independent examples. If there are only three positive examples, five validation folds cannot each contain one. Start with fewer folds if that fits the data, inspect each fold’s class counts, and report the limits of estimates based on so few positives.
Choose a metric that reflects the problem. If a rare defect matters, inspect recall or counts of missed defects alongside accuracy. Read the confusion matrix guide to see how those errors appear in a classification report.
Repeated measurements need group boundaries
Imagine a dataset of vibration readings from 15 machines. A random row split can place readings from the same machine in both training and validation. The model may recognize features specific to that machine. If you want to judge performance on unseen machines, use the machine ID as the group and keep each machine on one side of each split.
If class proportions also matter, a stratified group splitter can try to preserve them while respecting group boundaries. Check the resulting folds, especially when a few large groups contain most of the positive cases.
Forecasts need a time boundary
Suppose you forecast next week’s demand. Test with a sequence of historical cutoffs: train through one date, predict the following period, then move the cutoff forward. Set the validation horizon to reflect the forecast your team actually uses. If features or outcomes overlap across the boundary, consider a gap sized to that overlap.

Standard K-fold can validate on an earlier observation while training on later ones. A forward split keeps the direction of time intact. For an irregular time series, define comparable calendar windows if equal row counts would represent very different lengths of time.
Keep preprocessing inside each fold
Scaling, filling missing values with a learned average, and selecting features all use information from the data. If you do these steps before splitting, information from the validation fold can enter the training procedure. Fit those steps on the training portion of each fold, then apply them to that fold’s validation data.
A pipeline helps each fold repeat the same preprocessing and model fitting in the right order. Review identifiers, timestamps, and label-derived columns too. A clean split cannot rescue a feature that would be unavailable at prediction time. Scikit-learn guidance on data leakage.
Separate model selection from the final score
When you compare settings across the same folds, those results guide the choice of model. For a final estimate, evaluate the selected procedure on a test set that did not influence the choice. With limited data, nested cross-validation can serve a similar purpose: the inner folds select settings and the outer folds evaluate the selection procedure.
If a model keeps winning on training data and losing on validation data, examine model complexity and data coverage after checking the split. Read the guide to diagnosing overfitting.
Questions that come up before the first run
Is five-fold cross-validation always the best choice?
Five folds are a starting point for many independent datasets. Choose the count based on available examples, class frequencies, group counts, and training cost. For example, a project with only three independent groups cannot use five Group K-fold splits.
Should I deploy one of the models from the folds?
A common workflow uses the folds to choose the model settings, then refits with those settings on all available development data. Keep the independent test set reserved for reporting. If you deliberately deploy an ensemble of fold models, evaluate the actual ensemble as its own procedure.
Write down the split unit, the metric, and the reason for both before running the evaluation. Those details make a score easier to reproduce and help readers judge whether it answers the real prediction question.














