Training, validation and test sets
To tell whether a supervised model genuinely handles new cases, divide your labeled data into separate jobs: one part to learn from, one part to choose settings, and one held-out part for a final check.
Why one dataset is not enough.
Imagine preparing for a driving theory exam. You study from a practice sheet, take a few mock quizzes to see which topics need more work, and then sit a brand-new final exam you have never seen before.
Splitting data for a machine learning model follows a similar idea—but only as an analogy. A model does not study or reason like a person; it adjusts internal rules from past examples. If you score it only on the exact examples it learned from, a model that simply memorised past answers can look strong while struggling on new cases.
This lesson covers four ideas in order:
- Training set: the labeled examples the model learns patterns from.
- Validation set: separate examples used to compare options and tune model settings.
- Test set: separate examples held out until the end for a single final check on unseen cases.
- Reusing the test set: why repeatedly tweaking a model to raise its test score can make the result overly optimistic.
Maya (an invented character for this lesson) helps run a local library. Using an invented log of 100 past book loans—each labeled On time or Late—she wants a supervised model to predict which future loans may be returned late so staff can send reminders.
In this small example, Maya sets aside 60 loans for training, 20 for validation, and 20 for testing. Because 20 test loans is tiny—just one loan shifts the score by 5 percentage points—real projects usually use much larger datasets, though the three roles stay the same.

What each split is for.
Tell the three splits apart by one rule: the job the data does while you build and check the model.
Training set
Job: teach the model patterns connecting inputs to the recorded target.
In Maya’s library: 60 past loans the model uses to learn which loan lengths and book types tend to return late.
Outside example: past clinic appointments used to learn patterns behind missed visits.
Validation set
Job: compare model options and choose settings (such as how strict a rule should be) without touching the test set.
In Maya’s library: 20 separate loans used to compare Setting A, Setting B, and Setting C and pick the best one.
Outside example: a second batch of clinic records used to compare two reminder models before picking one.
Test set
Job: give a more reliable estimate of how the chosen model performs on unseen data after decisions are finished.
In Maya’s library: 20 untouched loans checked once at the end.
Outside example: a held-out month of clinic appointments checked once before the clinic rolls out reminders.
In this fixed three-way assignment, each example belongs to only one split so the same record is never both learned from and tested on. Names vary slightly across teams—many call the validation set the dev set—so focus on each split’s job.
Split ratios such as 60/20/20 or 80/10/10 are common starting points, not fixed rules. Very large datasets often use a much smaller share for validation and testing because even 1% can be thousands of examples, while small datasets sometimes use cross-validation (rotating examples through training and validation roles while still keeping the test set separate).
Why reusing the test set breaks the check.
It is tempting to think: “Why not check every tweak on the test set so I can see if the score goes up?” Once you use test-set results to guide changes, the test set stops being an unseen check and quietly becomes a tuning set.
Suppose Maya skips validation and tries Settings A, B, and C directly on her 20 test loans. She notices which specific loans Setting B missed, adds custom tweaks (Setting D) to fix those exact cases, and re-runs the same test set. The score jumps from 85% to 95%—not because Setting D understands new borrowers better, but because it was tailored to quirks of those 20 loans.
Think of a teacher handing out the real final exam paper every Friday so students can adjust their notes until they score 100%. That score shows how well they adapted to that specific paper—it can hide weak spots that show up on a fresh exam.
An untouched, representative test set gives a more reliable estimate—never a guarantee—of future performance. If the test score reveals a real problem and you need another round of model changes, treat the old test set as tuning data and collect fresh unseen examples for a new final check.

Try it: build splits and test the workflow.
Use the two-part lab below to practise assigning examples to splits and to see how reusing the test set changes the gap between test scores and fresh data.
Start with 10 invented loans (5 On time, 5 Late). Putting 6 in Training (3 On time, 3 Late), 2 in Validation (1 of each), and 2 in Test (1 of each) covers all three roles. Moving all 10 into Training leaves zero held-out loans to check how the model behaves on unseen cases.
- On 1. Assign examples to splits, try All in training (10 / 0 / 0) and Only On-time in test (6 / 2 / 2), then read the split diagnostic.
- Click individual Train, Val, or Test buttons on a few loans to fix any missing role or outcome.
- Switch to 2. Proper check vs reusing test, run the final Test check once for Setting B, and reveal next month’s new loans.
- Toggle to Reusing the test set (tune on Test), inspect Setting D (tweaked for Test), and reveal next month’s new loans to see the drop. Click Reset lab to start fresh.
All three roles are covered: Training has both outcomes to learn from, Validation can compare settings, and Test stays held out with both outcomes for a final check.
- Loan #1Mystery novel (14 days)On time
- Loan #2Exam study guide (7 days)Late
- Loan #3Children’s picture book (14 days)On time
- Loan #4Popular new release (7 days)Late
- Loan #5Gardening handbook (21 days)On time
- Loan #6Travel phrasebook (7 days)Late
- Loan #7Cookbook (14 days)On time
- Loan #8Local history book (14 days)Late
- Loan #9Biography (21 days)On time
- Loan #10DIY repair manual (7 days)Late
Illustrative simulation: these 10 loans and percentage scores are invented examples built to show split roles and test-set reuse, not measurements from a real library model.
Practical limits and quick questions.
A clean split protects your evaluation process, but it cannot solve every data problem on its own.
- Splitting does not fix unrepresentative data: if your original log misses a group of borrowers, every split will miss them too (Lesson 5.1).
- Respect time order when predicting the future: when patterns shift across seasons or months, splitting by date—training on earlier records and testing on later ones—matches how the model will be used. Deeper leakage problems are covered in Lesson 5.9.
- Small test sets are noisy: in Maya’s 20-loan test set, a single loan changes the score by 5 percentage points. Larger test sets give steadier estimates (and Lesson 5.8 covers metrics beyond simple accuracy).
- Can I skip the validation set if I am not comparing settings?
Yes. If you train one fixed model without tuning or choosing among options, a training/test split can be enough—most real projects still keep a validation set because they compare several choices.
- Why not train on 100% of the data so the model learns more?
Without held-out data, you have no reliable way to tell whether the model learned general patterns or simply memorised the examples it saw (more in Lesson 5.7).
- If my model scores poorly on the test set, is that data ruined?
No—you can inspect the errors or fold those records into future training or validation. You just need fresh unseen examples before calling a later score an unbiased final check.
Check your understanding.
Take this with you.
Separate learning, choosing, and checking. Use the training set to learn patterns, the validation set to compare options and tune settings, and a held-out test set once at the end for a more reliable estimate on unseen data—because reusing the test set to tune can inflate the score.
Ready to continue? Return to Data and Evaluation.