Lesson 2.6 · 8 min read · about 55 min to master at a very slow pace

Training, Validation and Test Sets

What each data split is for, typical split sizes, and why repeatedly checking the test set and picking the best model quietly ruins your performance estimate.

Not startedJump to quiz

Three sets, three jobs

SetUsed forRule
TrainingFitting the parameters (e.g. )Never the sole evidence of quality
ValidationComparing models, tuning hyperparameters (degree, , , threshold)Can be reused, but each reuse slightly overfits it
TestOne final, honest estimate of performance on new dataTouch it once, after all decisions are made
60:20:20
50:25:25
TrainingValidationTest
Common splits are 60:20:20 or 50:25:25, depending on how much data you have and how many models you compare. The ratio is a design choice, not a rule.

With and a 60:20:20 split you get 600 training, 200 validation and 200 test observations. After choosing, the final model is often re-trained on training + validation data.

The single most important rule of ML evaluation

You only get an unbiased estimate of performance by evaluating on data that played no role whatsoever in fitting or choosing the model.

Why picking the best test score is a leak

Scenario: 40 models

A bank has 10,000 records: 7,000 training, 1,500 validation, 1,500 test. A data scientist trains 40 models and checks each one's test accuracy: 85%, 87%, 89%, ..., up to 96% for model 40. They select model 40 and report 96%.

No model was trained on test rows, so where's the problem? The choice used the test set. Among 40 candidates, the winner partly won by luck on those particular 1,500 rows. That's selection bias: the reported 96% is too optimistic.

Correct: train on the training set, compare on the validation set (or by cross-validation), select the best, then evaluate that one model on the test set once.

Stratified splitting

When one class is rare (say 2% fraud), a random split can leave very few positives in a small validation or test set. A stratified split keeps the class proportions the same in every subset.

Stuck? Common doubts

Questions real learners asked while studying this lesson. They stay closed so they don't spoil your own thinking: open only the ones you need.

Going deeperWho actually "learns" the test set: the data scientist or the model?

The data scientist, or any automated selection procedure. Each of the 40 models is trained from scratch on the training data; none of them sees test rows or remembers earlier models.

But the person looks at test results and decides what to try next and which model to keep. Through those decisions, the overall development process adapts to the test set. Leakage happens through human (or automated) model-selection decisions, not through the training of any single model.

Going deeperWhy is choosing model 40 because it has the highest test accuracy a problem?

Repeatedly checking test results influences every later development decision, so the selection process indirectly fits the test set. With 40 tries, some models score well on that particular test set by chance. Picking the maximum keeps that luck, so the final reported test accuracy is overly optimistic: expect less on genuinely new data.

Cheatsheet

Train / validation / test

Train: fit parameters. Validation: choose models & hyperparameters. Test: final estimate, used once.

Typical splits

60:20:20 or 50:25:25 (train:val:test); train:val 50–80% / 20–50%. A design choice.

See every cheatsheet by category →

Check your understanding

Score 75% or more to master this lesson and earn XP. Answer first, then check.

Q1applyYou need to choose the polynomial degree for a regression. Which data should you use to make that choice?
Q2calculateYou have 1,000 observations and use a 60:20:20 train/validation/test split. How many observations are in the test set?
Q3diagnoseA team tries 40 model configurations, checks each on the test set, and reports the best test score as its expected performance. What's wrong?
Q4conceptOnly 2% of transactions are fraudulent. Why use a stratified split?
Q5applyYou've chosen a model and its hyperparameters using the validation set. What is a common next step before reporting performance?