"A model can fail in two opposite ways: by being too lazy to learn the pattern, or so obsessive that it memorizes the noise."
Explains the concepts of overfitting and underfitting in machine learning models.
Imagine studying for a driving test. If you learn only that "green means go," you'll miss lots of situations: that's underfitting. If you memorize the exact 50 practice questions and panic on a new one, that's overfitting.
In machine learning, we want a model that captures the real pattern in data and generalizes to new examples.
A classic clue is comparing training error and validation/test error:
The goal isn't to win on training data. It's to do well on tomorrow's data.
Think of fitting points on a graph. A straight line through curved data is like using a ruler to trace a rainbow: too rigid. A 15th-degree polynomial that wiggles through every point is like drawing squiggles to hit each dot exactly: too flexible.
This is the bias-variance tradeoff:
A simple way to measure error is:
error rate = wrong predictions / total predictions
Worked example:
If a model misses 18 out of 100 validation examples,
error rate = 18 / 100 = 0.18 = 18%
As model complexity increases, training error usually goes down. Validation error often goes down at first, then rises once the model starts fitting noise.
If a model underfits, make it more capable. If it overfits, make it less fragile.
To reduce underfitting:
To reduce overfitting:
Here's a tiny scikit-learn example using regularization:
from sklearn.linear_model import Ridge
model = Ridge(alpha=1.0) # larger alpha = more regularization
model.fit(X_train, y_train)
print(model.score(X_train, y_train))
print(model.score(X_val, y_val))
If alpha is too small, the model may overfit. If it's too large, the model may underfit.
Professionals rarely judge a model from one score. They look at training curves, validation metrics, and whether the pattern makes sense.
A practical checklist:
alpha, epochsA useful mental image: underfitting is wearing blurry glasses; overfitting is zooming in so far that dust looks like the map. In both cases, you lose the real structure.
The winning model doesn't memorize yesterday's examples. It learns the rule that generated them.
Test your understanding with inline MCQs, track your mastery score, and get scheduled review reminders — free.
Start learning for free