Skip to content

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.

Introductory ~10 min8 steps

What runs in CodeSplash

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

Read first

01

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.

Validation fold stripWhich rows train, validate and test in each fold — and is anything leaking across time or groups?
View data
foldrows in time order (binned)trainvalidationtestexcluded
Final050000
Final150000
Final250000
Final350000
Final450000
Final550000
Final650000
Final750000
Final850000
Final950000
Final1050000
Final1150000
Final1250000
Final1348002
Final1450000
Final1550000
Final1650000
Final1750000
Final1850000
Final1950000
Final2050000
Final2150000
Final2250000
Final2348002
Final2450000
Final2550000
Final2650000
Final2750000
Final2850000
Final2948002
Final3050000
Final3150000
Final3250000
Final3350000
Final3450000
Final3550000
Final3650000
Final3750000
Final3850000
Final3950000
Final4050000
Final4150000
Final4248002
Final4350000
Final4450000
Final4550000
Final4650000
Final4750000
Final4800500
Final4900500
Final5000500
Final5100500
Final5200500
Final5300500
Final5400500
Final5500500
Final5600500
Final5700500
Final5800500
Final5900500

First 60 of 300 rows.

02

Which model is better?

Predict

Predict 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?

The forest: it wins on the test rowsBoosting: it wins in cross-validationYou can't separate them from these numbers
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.

03

Few test rows, much noise

Read

A 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.

04

Peeking

Explore

Nested 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?

How sure?

Scheme

5
40
Simulating…

Commit your prediction above to see the result

Make your prediction first; the figure appears when you commit.

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.

05

A rule to work by

Read
  1. Fix the split before you look at results.
  2. Choose by cross-validation.
  3. 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.

06

Check your understanding

Checkpoint

Check 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.

07

Find the lock

In the app

In 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.

08

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