Step 2 of 6
If we test a model on the same emails it studied, we only learn whether it memorised them. So before any training, we split the 500 labelled emails into three separate piles and give each pile a different job.
300 emails (60%)
120 spam · 180 not spam
The model studies these emails and their labels to learn patterns.
Think: practice problems with an answer key.
100 emails (20%)
40 spam · 60 not spam
We try versions of the model here, compare them and tune settings. The model never learns from these emails.
Think: a mock exam you can retake after studying.
100 emails (20%)
40 spam · 60 not spam
Locked away until the end. One run gives an honest estimate of how the model behaves on emails it has never seen.
Think: the final exam, taken once.
The assignment is random but stratified: every set has the same 40% spam share. If the test set happened to be 10% spam, its precision and recall would not be comparable with the others. We also fixed a random seed so the split can be reproduced.
There is no universal rule. The goal is for validation and test to be big enough to give stable numbers, while leaving as much data as possible to learn from. The more data you have, the smaller the evaluation percentages can be. Try the presets:
When it fits: Small datasets (hundreds to a few thousand rows). This is what we use: validation and test need enough examples to be meaningful.
Our split is small, and that matters
With only 100 emails in validation and 100 in test, each set holds just 40 spam emails. Missing one spam email moves recall by 2.5 points, so small differences between versions can be noise. We come back to this on the blind-test step.
Split before you look
Decide the split before any feature engineering or tuning, and never move emails between sets afterwards.
Stratify by label
Keep the spam/not-spam ratio the same in every set so metrics are comparable.
Prevent leakage
The same email, near-duplicates (a campaign sent to 1,000 people) or the same sender thread must not straddle sets. Otherwise the test is secretly a re-run of training.
Mimic production
If your model will score tomorrow’s email, evaluate on a later time window than you train on. Spammers change tactics, and a random split hides that drift.
Touch the test set once
Every peek that leads to a change turns the test set into a second validation set. Keep it blind until you have a final candidate.
Write the seed down
A fixed random seed makes the split reproducible, so results can be audited and compared later.