Understanding AI · lesson 21 of 60 · about 5 minutes
Overfitting
A model that memorises its examples looks perfect in training and fails in the real world. Learn to spot it.
What you'll learn
- Explain what overfitting means
- Spot overfitting from training and test scores
- Explain why simpler patterns often work better
Memorising the answers
Imagine a student who memorises last year's exam answers word for word. They'd ace that exact exam and fail a new one. They memorised instead of understanding.
Models can do the same. A model that learns every quirk and accident in its training examples is overfitting. It scores brilliantly on training data and badly on anything new.
The tell-tale sign
Overfitting shows up as a big gap: very high accuracy on training examples, much lower on new test examples. A model that learned the real pattern scores similarly on both.
Comparing two models' scores. A big gap between training and test means overfitting.
models = {"A": (99, 62), "B": (88, 85)}
for name, scores in models.items():
train, test = scores
print(name, "gap:", train - test)Output
A gap: 37
B gap: 3Tip
items() goes through a dictionary's names and values together.
Now try it yourself
This lesson is free in Codiqo, with 6 questions on what you just read. You can only learn to code by writing code, so it ends with a short program you write yourself, which we run and check straight away.