Machine Learning / Models and controlled selection / Lesson 14
Interpreting Cross-Validation Variation
Compare fold-level model results while respecting split design and uncertainty.
On this page
Lesson goals
- Inspect fold scores as well as their mean.
- Choose split units that match the intended deployment.
- Separate model selection from final evaluation.
Use folds to test a deployment boundary
Cross-validation evaluates a training procedure repeatedly using different held-out partitions. Choose a split that resembles deployment: records from the same person may need to stay together when predicting for new people, while future prediction requires time-respecting partitions. Random folds can be misleading when records share information or features contain later events.
Fit preprocessing and feature selection inside each training fold, not once on the entire dataset. Otherwise information from the held-out fold can influence the fitted pipeline. Keep the metric and population explicit so fold scores can be interpreted in the context of the decision.
Inspect the distribution, not only the mean
In this synthetic example both candidates have the same mean score, but the complex candidate varies more across the three folds. The values are illustrative rather than actual model results. Examine the individual folds, sample sizes, and difficult groups before assuming the two procedures have equivalent reliability.
fold_scores = {"simple": [0.76, 0.80, 0.78], "complex": [0.84, 0.66, 0.84]}
for name, scores in fold_scores.items():
print(name, round(sum(scores) / len(scores), 2), min(scores), max(scores))
Both means are 0.78; the complex candidate ranges from 0.66 to 0.84, while the simple candidate ranges from 0.76 to 0.80.
Investigate why scores differ
Fold variation may reflect different group composition, sample size, temporal conditions, or unstable training. The range is a descriptive diagnostic, not a confidence interval. Inspect errors and class counts for each fold and check that no group or future information crosses the intended boundary before attributing variation to the model.
scores = [0.76, 0.80, 0.78]
print("range", round(max(scores) - min(scores), 2))
print("folds", len(scores))
The simple candidate has three scores and a range of 0.04; this calculation alone does not quantify deployment uncertainty.
Keep model selection separate
Use the same folds and metric when comparing candidate procedures. Searching many configurations can make the best observed validation score optimistic because selection favors favorable noise. Reserve a separate test set or use an appropriate nested evaluation when estimating the complete selection procedure. Do not repeatedly adjust the method against the final test.
Report the evidence and limits
Record the split rule, fold counts, metric, preprocessing, candidate search, and per-fold results. Compare with a meaningful baseline and describe where performance is weak. A fold average is not a guarantee for a future population; collect independent evidence when the deployment distribution, prevalence, or outcome process differs.
Common errors and fixes
Validation scores are unexpectedly high.
- Why it happens
- Related entities or future information appear on both sides of a split.
- How to fix it
- Redesign the split around the deployment boundary and refit the pipeline.
- Prevent it next time
- Audit group and time overlap before training.
Two candidates have the same mean but very different fold behavior.
- Why it happens
- Only the average was reviewed.
- How to fix it
- Inspect fold scores, sizes, and errors for each candidate.
- Prevent it next time
- Retain fold-level results with the experiment record.
The reported test score improves after repeated tuning.
- Why it happens
- The final test set was used for model selection.
- How to fix it
- Evaluate the selected procedure on a new independent test set when available.
- Prevent it next time
- Reserve the final test and predefine its use.
2 practice exercises
1. Two candidates have fold scores 0.76, 0.80, 0.78 and 0.84, 0.66, 0.84. What differs?
Show worked solution
Both means are 0.78, but the second range is 0.18 versus 0.04 for the first. Investigate fold composition and errors before deciding which procedure better meets the goal.
2. Several records belong to each customer and the model will score new customers. How should the split be checked?
Show worked solution
Keep each customer in one side of a fold and verify there is no customer overlap. Fit preprocessing within the training portion and compare held-out customers using the intended metric.
Key takeaways
- A split should reproduce the intended deployment boundary.
- Fold variation is evidence to investigate, not a confidence interval by itself.
- Preserve an independent evaluation for the selected procedure.