Split Train, Validation & Test
Why you need three sets, not one.
Split Train, Validation & Test is a free Deep Learning Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Deep Learning Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
One Pile Is Not Enough
If you train and judge a model on the same data, you only learn that it memorized those rows. To trust it, you must split your data into separate roles.
Meet the Training Set
The training set is the data your model actually learns from. Its weights are nudged again and again to fit exactly these examples well.
Meet the Validation Set
The validation set is held back during training and checked along the way. It tells you how the model does on data it has never updated on.
Meet the Test Set
The test set is touched once, at the very end. It gives an honest, final score after every choice has already been made.
Why Validation Is Separate
You tune knobs like learning rate by watching validation results. That quietly leaks the validation set into your choices, so it can no longer be a clean final judge.
The Test Set Stays Sealed
Because validation guided your decisions, you need one untouched pile for the truth. Keep the test set sealed until you are completely done.
A Common Split
A typical starting point is roughly 80/10/10: most data for training, smaller slices for validation and test. Adjust based on how much data you have.
Split with random_split
PyTorch gives you random_split to carve a dataset into pieces by length. It shuffles which samples land in each set for you.
from torch.utils.data import random_split
train, val, test = random_split(ds, [800, 100, 100])Seed for Reproducible Splits
The split is random, so set a seed if you want the same pieces every run. That keeps experiments comparable across sessions.
g = torch.Generator().manual_seed(42)
train, val, test = random_split(ds, [800, 100, 100], generator=g)Stratify for Balance
With rare classes, a plain random split may leave some out. Stratifying keeps each set's class mix close to the original so scores stay meaningful.
Never Peek at Test
The golden rule is simple: do not let the test set shape any decision. The moment it does, your final number stops being trustworthy.
Quick Check
Which set should you look at only once, at the very end?
Recap
Three sets, three jobs: training teaches the model, validation guides your tuning, and test gives the final honest score. Keep test sealed until the end. 🎯
Frequently asked questions
Is the “Split Train, Validation & Test” lesson free?
Yes — the full text of “Split Train, Validation & Test” is free to read here on the web, and the Deep Learning Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Deep Learning Academy course, upgrade to CoddyKit PRO.
What will I learn in “Split Train, Validation & Test”?
Why you need three sets, not one. You practise Deep Learning Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Deep Learning Academy?
No prior experience is required. Deep Learning Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Split Train, Validation & Test” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Deep Learning Academy lesson?
Yes. Every Deep Learning Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Split Train, Validation & Test
- An Epoch Loop with Validation
- Save & Load with state_dict
- Early Stopping on Val Loss