Module 2 · How Machine Learning Works
Why Models Fail: Overfitting, Underfitting, Bias & Generalization
65 min
Learning objectives
- Define overfitting and underfitting and recognize their symptoms
- Explain why models are tested on held-out data and what generalization means
- Describe how bias enters models through data and why high accuracy can still be misleading
The real goal: generalization
It's easy to build a model that does well on the data it studied. The hard, valuable thing is a model that does well on new data it has never seen — that's generalization, and it's the entire point. A model that aces the examples it memorized but flops in the real world is useless. So practitioners always hold back some data to test honestly.
Generalization — A model's ability to perform well on new, unseen data — not just the data it was trained on.
Overfitting: memorizing instead of learning
Overfitting happens when a model learns the training data too literally — including its random noise and quirks — instead of the underlying pattern. It looks brilliant on training data and disappoints on new data. Overfitting is common with overly complex models or too little data.
Analogy
Overfitting is like a student who memorizes the exact answers to last year's exam. They score perfectly on the practice test but fall apart when this year's questions are worded differently. They memorized; they didn't learn.
Underfitting: too simple to capture the pattern
Underfitting is the opposite problem: the model is too simple, or trained too little, to capture the real relationship in the data. It does poorly on both training and new data. If overfitting is memorizing, underfitting is barely showing up to study.
| Symptom | Overfitting | Underfitting |
|---|---|---|
| Training accuracy | High | Low |
| New-data accuracy | Low (big drop) | Low |
| Likely cause | Model too complex / too little data | Model too simple / undertrained |
| Fix direction | Simplify, add data, regularize | Add capacity, better features, train more |
The art of ML is balancing these two. You want a model complex enough to capture the real pattern but not so complex it memorizes noise. The held-out test set is how you tell which side you're on.
How we catch these problems: held-out data
To measure generalization honestly, data is split: the model learns on a training set, and is then evaluated on a test set it never saw. A large gap — great on training, poor on test — is the fingerprint of overfitting. Reporting accuracy only on data the model trained on is a classic mistake that makes a weak model look strong.
Bias: when the data itself is the problem
A model learns whatever patterns are in its data — including unfair or unrepresentative ones. If historical hiring data favored one group, a model trained on it can learn to do the same, even if no one intended it. Bias is not usually a flaw in the algorithm; it's a reflection of biased or incomplete data. This is why representative data and careful evaluation matter so much.
Watch out
High overall accuracy can hide serious failures. A model that is 95% accurate overall might be far worse for a specific subgroup, or might score well only because the problem is lopsided (predicting 'not fraud' for everything looks accurate if fraud is rare). Always look beneath the single headline number.
Example — The accuracy trap
If only 1 in 1,000 transactions is fraud, a model that always says 'not fraud' is 99.9% accurate — and completely worthless, because it never catches a single fraud. Accuracy alone can be deeply misleading on imbalanced problems.
Knowledge check
Quick practice — not part of your exam score.
A model scores 99% on its training data but only 70% on data it never saw. This is a classic sign of:
Why do practitioners evaluate a model on a separate test set rather than on its training data?
Fraud occurs in 0.1% of transactions. A model that simply labels every transaction 'not fraud' reports 99.9% accuracy. What is the main lesson?
Sign in to track your progress and mark lessons complete.
Sign in