The locked test set
Hold rows back, choose with cross-validation, and look at the test score once. See how noisy a small test set is, and why peeking spends it.
What runs in CodeSplash
- Random forest Verified in Python and R
- Histogram gradient boosting Verified in Python and R
- Baseline (no features) Verified in Python and R
You will be able to
- Separate the roles of training, validation and test rows
- Explain why a test score used for choosing stops being honest
- Judge how much a test score on few rows can be trusted
Three jobs, three sets of rows
Read- Training rows fit the model.
- Validation rows choose between models and settings. In cross-validation, each training row takes a turn.
- The locked test setLocked test setRows held back from fitting and choosing, for one final score on the model you picked. gives one final score for the one model you chose.
Each set answers a different question. Once rows have helped you decide, they can no longer tell you how good that decision was.
View data
| fold | rows in time order (binned) | train | validation | test | excluded |
|---|---|---|---|---|---|
| Final | 0 | 50 | 0 | 0 | 0 |
| Final | 1 | 50 | 0 | 0 | 0 |
| Final | 2 | 50 | 0 | 0 | 0 |
| Final | 3 | 50 | 0 | 0 | 0 |
| Final | 4 | 50 | 0 | 0 | 0 |
| Final | 5 | 50 | 0 | 0 | 0 |
| Final | 6 | 50 | 0 | 0 | 0 |
| Final | 7 | 50 | 0 | 0 | 0 |
| Final | 8 | 50 | 0 | 0 | 0 |
| Final | 9 | 50 | 0 | 0 | 0 |
| Final | 10 | 50 | 0 | 0 | 0 |
| Final | 11 | 50 | 0 | 0 | 0 |
| Final | 12 | 50 | 0 | 0 | 0 |
| Final | 13 | 48 | 0 | 0 | 2 |
| Final | 14 | 50 | 0 | 0 | 0 |
| Final | 15 | 50 | 0 | 0 | 0 |
| Final | 16 | 50 | 0 | 0 | 0 |
| Final | 17 | 50 | 0 | 0 | 0 |
| Final | 18 | 50 | 0 | 0 | 0 |
| Final | 19 | 50 | 0 | 0 | 0 |
| Final | 20 | 50 | 0 | 0 | 0 |
| Final | 21 | 50 | 0 | 0 | 0 |
| Final | 22 | 50 | 0 | 0 | 0 |
| Final | 23 | 48 | 0 | 0 | 2 |
| Final | 24 | 50 | 0 | 0 | 0 |
| Final | 25 | 50 | 0 | 0 | 0 |
| Final | 26 | 50 | 0 | 0 | 0 |
| Final | 27 | 50 | 0 | 0 | 0 |
| Final | 28 | 50 | 0 | 0 | 0 |
| Final | 29 | 48 | 0 | 0 | 2 |
| Final | 30 | 50 | 0 | 0 | 0 |
| Final | 31 | 50 | 0 | 0 | 0 |
| Final | 32 | 50 | 0 | 0 | 0 |
| Final | 33 | 50 | 0 | 0 | 0 |
| Final | 34 | 50 | 0 | 0 | 0 |
| Final | 35 | 50 | 0 | 0 | 0 |
| Final | 36 | 50 | 0 | 0 | 0 |
| Final | 37 | 50 | 0 | 0 | 0 |
| Final | 38 | 50 | 0 | 0 | 0 |
| Final | 39 | 50 | 0 | 0 | 0 |
| Final | 40 | 50 | 0 | 0 | 0 |
| Final | 41 | 50 | 0 | 0 | 0 |
| Final | 42 | 48 | 0 | 0 | 2 |
| Final | 43 | 50 | 0 | 0 | 0 |
| Final | 44 | 50 | 0 | 0 | 0 |
| Final | 45 | 50 | 0 | 0 | 0 |
| Final | 46 | 50 | 0 | 0 | 0 |
| Final | 47 | 50 | 0 | 0 | 0 |
| Final | 48 | 0 | 0 | 50 | 0 |
| Final | 49 | 0 | 0 | 50 | 0 |
| Final | 50 | 0 | 0 | 50 | 0 |
| Final | 51 | 0 | 0 | 50 | 0 |
| Final | 52 | 0 | 0 | 50 | 0 |
| Final | 53 | 0 | 0 | 50 | 0 |
| Final | 54 | 0 | 0 | 50 | 0 |
| Final | 55 | 0 | 0 | 50 | 0 |
| Final | 56 | 0 | 0 | 50 | 0 |
| Final | 57 | 0 | 0 | 50 | 0 |
| Final | 58 | 0 | 0 | 50 | 0 |
| Final | 59 | 0 | 0 | 50 | 0 |
First 60 of 300 rows.
Which model is better?
PredictPredict first
Ozone, 23 test rows. A random forest has a cross-validated RMSE of 19.0 and a test RMSE of 14.0. Histogram boosting has 18.4 and 20.0. Which is better?
Reveal
You can't separate them. Cross-validation calls them close, and the test scores differ by a lot on few rows. The no-feature baseline gets 34.6 in cross-validation but 23.7 on these same test rows: this draw of rows happens to be easier.
Few test rows, much noise
ReadA test score is an estimate with its own uncertainty. It shrinks slowly: to halve the noise you need about four times the rows.
So a 20% test set on a small table can move a lot by chance. That doesn't make it useless. It's an unbiased check that the model isn't badly broken, not a contest that ranks close models.
When rows are few, lean on repeated cross-validation to compare, and read the final test score as one noisy confirmation.
Peeking
ExploreNested in this explorable shows what happens when you report the best score from a search. Compare The shortcut with True new-data error.
DExplorable · Cross-validation folds
Which rows should be held out so the score predicts real performance?
Each scheme has a tempting shortcut: training error, plain random folds, or the best score from a search. Will the shortcut here look better than the true error on new data?
Scheme
Commit your prediction above to see the result
Make your prediction to see the result.
Looking at a test score and then changing the model does the same thing, more slowly. Every look lets noise steer your choice, so the score drifts below the truth. Raise Rows n to see how the size of the optimism depends on how many rows you have.
A rule to work by
Read- Fix the split before you look at results.
- Choose by cross-validation.
- Look at the test score at the end, and report it even if it's disappointing.
If you did change something after looking, say so. Then find fresh rows, such as a later time window, for a new honest score.
Check your understanding
CheckpointCheck yourself
You tune 40 settings, and for each you look at the test score. You keep the one with the best test score and report that score. What's wrong?
Show the answer
Answer: b
Training on rows and choosing with rows both leak information. A number used to select can't also be an unbiased report of the selection.
Check yourself
Which rows should decide between a forest and a boosted model?
Show the answer
Answer: b
Cross-validated scores on shared folds are for choosing. Test rows are for the one final look.
Check yourself
To cut the noise in a test score roughly in half, about how many times more test rows do you need?
Show the answer
Answer: 4
Noise in an average falls with the square root of the rows, so half the noise takes four times the rows.
Find the lock
In the appIn Validation, Locked test set sets the share held back, and Split plan draws it in a strip. Test set touched counts the looks: every run that scores the test rows adds one. The Leaderboard shows the same count, next to the Test column you should read last. The walkthrough tunes a model of {{target}} on these folds and leaves the test rows alone.
Recap
Recap- Training fits, validation chooses, and the locked test set reports once.
- A score used to choose stops being honest.
- A test score on few rows is noisy: it confirms, it doesn't rank close models.
Concepts in this lesson