Held-Out Test
You'll train a classifier with a split you can defend, leak into the test set on purpose, and learn to spot the leak from the score alone.
About
The most common mistake in machine learning is letting the model see the test set, usually by accident, and the score looks great right up until the model meets real data. This badge has you do it wrong deliberately, so you know what a leak looks like, and then do it right. Pick a free tabular dataset with a few thousand rows and a real question, like whether a passenger survived, whether a customer left, or whether a mushroom is edible. What counts is a train, validation and test split made before anything else, a preprocessing step fitted only on training rows, and one honest number at the end that you computed exactly once.
At a glance
- Per requirement
- 25 XP
- Completion bonus
- 150 XP
- Requirements
- 5
- Takes
- One weekend
- Skill level
- Intermediate (months of practice)
- Cost
- Free
- Supplies
- Nothing special
- Where
- At home
- Other people
- On your own
Requirements
-
1
Split into train, validation and test before you look at a single feature. 60, 20 and 20 percent is fine. Set a random seed so you can redo it, and write the three row counts and the seed in a notes file. Then put the test rows somewhere you won't touch until the last requirement. If the dataset has a time column or the same people appearing more than once, split by time or by person rather than by row, or the same person ends up on both sides. Take a screenshot of the three counts and the seed. Photo
-
2
Leak on purpose: scale and fill missing values using every row, then train and score. Compute the column means and standard deviations across all rows, including the ones you set aside, fill the gaps, scale, train a model, and score it on the validation rows. Write the number down. This is how a lot of tutorials do it, and the leak is small but real. Then do a worse one: add the target column as a feature under a different name and watch validation accuracy hit 100 percent. The test rows stay untouched through all of this. Take a screenshot of both scores. Photo
-
3
Do it right: fit every preprocessing step on training rows only. Means, scalers, imputers, category encodings and anything else that learns from data get fitted on the training split and then applied to validation and test. A pipeline object in your library does this for you and is worth learning. Score on the validation set, not the test set. Take a screenshot of the pipeline code and the validation score. Photo
-
4
Hunt for a feature that is secretly the answer. Rank your features by importance or by single-feature accuracy. Anything near perfect on its own is suspicious: a 'date closed' column predicts whether a loan defaulted because it only exists for closed loans. Find one such column in your dataset or in a second one, remove it, and note how the score drops. Take a screenshot of the ranking with the leaky feature highlighted. Photo
-
5
Tune on validation, then score the test set exactly once. Try three or four model settings and pick the best on validation. Then, and only then, run the test rows through it, write the number down, and stop. If you're tempted to go back and change something after seeing the test score, that's the moment the test set stops being a test set. Post the validation and test scores together with your majority baseline and two sentences on how far apart they are. Photo