Machine Learning BasicsLesson 4
Lesson 48 min
Train / Test Split
Why you must evaluate on data the model has never seen.
What you will learn
- ✓Why a test set is essential
- ✓Typical split ratios
- ✓What data leakage is
Explanation
If you test a model on the same data it trained on, it can simply memorise and look perfect — but fail on new data. So you split the data first.
A common split is 80% train, 20% test. The model never sees the test set during training, so its test score estimates real-world performance.
Watch out for data leakage — accidentally letting test information influence training (e.g. scaling using the whole dataset). It produces falsely high scores.
Code Example
python
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
Real-world use
A model that scores 99% on training data but 60% on the test set is overfitting — the split is what reveals it.
Common mistakes
- • Reporting the training-set score and calling it the model's accuracy.
Practice
Split any dataset 80/20 and note how the train and test accuracies differ.
Knowledge check
0/1 answered1. Why hold out a test set?
Answer all questions to check.