Model Calibration
The test set should not be used to guide model calibration.
Try it: K-Fold Cross-Validation and Model Selection
How hold-out and k-fold cross-validation choose among candidate models: each fold takes a turn as the validation set, the fold errors are averaged, the lowest average picks the model, and only then is the untouched test set used once — while tuning on the test set would report an optimistic number.
How it works
- Set 10 test points aside; they take no part in any choice.
- Optionally shuffle the 20 development points (seeded), then cut them into k folds (hold-out: one chunk validates, the rest trains).
- For every round, train each candidate polynomial on the other folds and measure its validation MSE on the held-out fold.
- Average each candidate's fold errors (with repeated shuffling: average the p run scores; p × k fits per candidate).
- Select the candidate with the lowest average, retrain it on all development points, and evaluate it once on the test set.
- For contrast, show which candidate the test set itself would have picked — that figure is leaked and optimistic.
Default run (12 steps): 20 development points (sorted by x as they arrived) and 10 test points set aside. Candidates: polynomial degree 0, 1, 2, 3, 4, 5, 6. Plan: 5-fold cross-validation, shuffled with seed 1 → 5 fits per candidate (p × k = 1 × 5), 35 in total. … 5-fold cross-validation picks degree 3 (score 0.0768); its honest test MSE is 0.0889. Picking by test error would report degree 4 at 0.0868 — a leaked, optimistic figure.
Simplified: One fixed toy dataset (20 development + 10 test points from sin(2πx) with noise) and polynomial least squares of degree 0–6 as the candidate models. Shuffling uses a seeded mulberry32 Fisher–Yates; folds are contiguous chunks like scikit-learn's KFold. Hold-out uses the first of k chunks as the validation set.
Loading the simulation…
The Protected Final Check
Model calibration means making choices or adjustments while developing a model. The central rule is that the test set should not guide those choices. If test results influence decisions about the model, the test set is no longer being held aside for an independent final evaluation.
Hold-Out Roles
The simplest validation protocol divides the available examples into three roles. Training data is used to build the model. Validation data is used while choosing or adjusting the model. Test data is held aside for the final performance measurement. This three-way separation is needed because a two-way division into training and test data is not enough when decisions are still being made.
A Three-Way Development Plan
Suppose a learner has a dataset and is still deciding between different model choices. Which role should each portion play?
- 1Build
Use the training portion to build the candidate model.
- 2Choose
Use the validation portion to compare or adjust candidate choices during development.
- 3Protect
Do not use the test portion to guide those choices. Keep it aside for the final evaluation.
The validation portion supports calibration, while the test portion remains an independent final check.
Rotating K-Fold Evaluation
K-fold validation addresses some of the split-dependent variation of a single hold-out split. The data is divided into K equal partitions. One partition takes the validation role while the remaining partitions are used for training. The validation role then rotates so that each partition takes a turn. The resulting scores are averaged.
Four Partitions, Four Validation Turns
Imagine a K-fold process with four equal partitions.
- 1Run 1
Partition 1 is used for validation, and the other three partitions are used for training.
- 2Run 2
Partition 2 becomes the validation partition, while the other three are used for training.
- 3Run 3
Partition 3 takes the validation role, and the remaining partitions are used for training.
- 4Run 4
Partition 4 takes the validation role, and the remaining partitions are used for training.
- 5Combine
Average the four resulting validation scores.
Every partition contributes a validation result, rather than relying on only one fixed validation portion.
Repeated Partitioning
When the dataset is especially small and a more precise evaluation is needed, K-fold validation can be repeated. Before each new run, the data is shuffled and divided into K partitions again. Each run therefore produces its own K-fold score. The final score is the average of the scores from all runs.
A single K-fold run explores one partition arrangement. Repeating the process exposes the evaluation to additional arrangements. This can help when performance measurements change substantially after different random shuffling and splitting choices.
The Cost of More Evidence
| Protocol | Partition behavior | Evaluation result | Computational implication |
|---|---|---|---|
| Simple hold-out | One fixed separation into training, validation, and test roles | One validation measurement and a final test measurement | Simplest protocol |
| K-fold validation | The validation role rotates across K equal partitions | Average of the K resulting scores | Requires training and evaluating K models for one K-fold run |
| Repeated K-fold validation | Shuffle and repartition before each K-fold run | Average the scores from all runs | Repeating the process P times requires training and evaluating P multiplied by K models |
The protocols trade simplicity and computational cost against exposure to different partition arrangements.
The benefit of repeated validation has a direct cost. One K-fold run requires training and evaluating models for each of its K partitions. If the process is repeated P times, the total number of trained and evaluated models is P multiplied by K. Repetition can provide more exposure to different splits, but it requires more computation.
Mistakes in Calibration
Common mistake Using the test score to choose or adjust the model
What it looks likeA developer compares several model choices using the test results and keeps the choice with the best test score.
Why it failsThe test set has influenced the model decision, so it is no longer an independent final evaluation.
Do this insteadUse a separate validation set to guide calibration and reserve the test set for the final measurement.
Common mistake Assuming a single hold-out split is always reliable
What it looks likeA small dataset produces a very different performance measurement after another random shuffle and split.
Why it failsSmall validation and test portions may not represent the broader data well.
Do this insteadTreat instability across splitting rounds as a warning sign and consider K-fold validation.
Common mistake Confusing K-fold validation with one fixed validation split
What it looks likeOnly one partition is ever evaluated while all other partitions are used for training.
Why it failsThat does not rotate the evaluation role across K partitions.
Do this insteadLet each partition take a turn as validation, then average the resulting scores.
Common mistake Ignoring the cost of repeated K-fold validation
What it looks likeA process is repeated several times without accounting for the additional model training and evaluation.
Why it failsEach repetition performs another K-fold process.
Do this insteadRemember that P repetitions with K partitions require training and evaluating P multiplied by K models.
Choose the Validation Protocol
A dataset is very small, and performance measurements change noticeably after different random shuffling and splitting rounds. The test set has not yet been used. Which validation approach is the strongest candidate, and what trade-off should be explained?
Hints
- Look for the method designed to respond to split-dependent variation.
- Consider what happens when the K-fold process is repeated several times.
Selecting a More Stable Evaluation Process
A small dataset produces unstable measurements under different hold-out splits. What process should be considered?
- 1Identify the warning sign
Large changes between random splitting rounds indicate split-dependent variation.
- 2Use rotating evaluation
K-fold validation allows more portions of the data to take part in evaluation by rotating the validation role.
- 3Consider repetition
If the dataset is especially small and more precise evaluation is needed, shuffle and repartition before additional K-fold runs.
- 4State the trade-off
Additional runs expose evaluation to more partition arrangements but require training and evaluating more models.
K-fold validation, possibly repeated with shuffling, addresses split-dependent variation at increased computational cost.
Key Takeaways
- 1Do not use test results to guide model calibration; reserve the test set for an independent final evaluation.
- 2Simple hold-out validation separates training, validation, and test roles.
- 3K-fold validation rotates the validation role across equal partitions and averages the resulting scores.
- 4Repeated K-fold validation reshuffles and repartitions the data before each run, then averages the run scores.
- 5Repeated validation can reduce dependence on one partition arrangement, but it increases computation because P repetitions with K partitions require P multiplied by K model runs.
At a glance
- The test set must remain separate from calibration decisions.
- Hold-out validation gives training, validation, and test data distinct roles.
- K-fold validation rotates evaluation across K partitions and averages the scores.
- Repeated K-fold validation uses new shuffles and partitions for additional runs.
- More validation runs provide more split arrangements but increase computational cost.