Skip to content
Road to Intelligence

Concept · Chapter 3: Machine Learning

Generalization, Overfitting and Underfitting

Must knowKnow well35 minDifficulty

The goal of learning is generalization — good performance on data the model has never seen — and a model that memorizes its training data (overfits) or is too simple to capture the pattern (underfits) fails at it.

The problem

A model can always fit its training data better by becoming more complex, but fitting the training data is not the goal; predicting new data is.

The solution

Measure performance on held-out data the model never trained on: split into train/validation/test (or cross-validate), choose model complexity and hyperparameters on validation, and report the final score on the untouched test set.

The consequence

Held-out evaluation became the foundation of empirical ML — and when test sets leak into training (contamination) or get reused too often, reported results stop meaning anything.

Intuition

A student who memorizes last year's exam answers scores 100% on last year's exam and fails this year's. Another who only learned "the answer is usually C" does badly on both. The one who understood the material does well on both. Generalization is doing well on questions you haven't seen.

Try it

Try it · toy model

Overfitting Lab

Fit curves of increasing complexity to 12 noisy points. Training error keeps falling; error on new data falls, then soars. Then add regularization.

Know well8 min

What the lab shows, precisely: as the polynomial degree rises, training error only ever goes down — at degree 11, with 12 coefficients for 12 points, the curve passes through every training point exactly. Test error falls, then rises, and at high degree it explodes. The sweet spot is in the middle.

The bias–variance decomposition

For squared error, the expected error on a new point splits into three parts:

E[(y−f^(x))2]=Bias[f^(x)]2⏟too simple+Var[f^(x)]⏟too sensitive+σ2⏟noise\mathbb{E}\big[(y - \hat{f}(x))^2\big] = \underbrace{\text{Bias}[\hat f(x)]^2}_{\text{too simple}} + \underbrace{\text{Var}[\hat f(x)]}_{\text{too sensitive}} + \underbrace{\sigma^2}_{\text{noise}}

The discipline: train, validation, test

  1. Train set

    Fit the model's parameters.
  2. Validation set

    Choose everything else — model type, degree, regularization strength, when to stop. (With little data, rotate this role with k-fold cross-validation.)
  3. Test set

    Evaluate once, at the end. If you look at test results and go back to change things, the test set has become a validation set, and your final number is optimistic.

Very large neural networks can have far more parameters than training examples and still generalize well Established — behaviour the classical U-curve doesn't predict (sometimes called double descent). Exactly why is still being studied Active research. The practical discipline above applies either way.

Why should I care?

As a researcher

Every claim in an ML paper is a claim about generalization. Knowing how train/validation/test discipline breaks down (tuning on test, contamination) is how you judge whether a result is real.

As an engineer

A model that looks great offline and fails in production has usually overfit, leaked, or met a shifted distribution. Validation discipline is the cheapest insurance you have.

Modern systems that depend on it

  • Model selection and hyperparameter tuning
  • Regularization
  • Benchmark design
  • Contamination analysis for LLMs

Historical context

Before

Statistics dealt with the same trade-off as model selection (e.g. choosing how many parameters to fit).

After

Regularization, cross-validation, early stopping; later, the surprising behaviour of very large models ('double descent'), which still generalize while having more parameters than data points.

Used today

Every trained model, from a churn predictor to an LLM, is evaluated on held-out data — and benchmark contamination is a central worry in LLM evaluation.

What to remember

  • Training error measures memorization; held-out error measures learning.
  • Underfitting: too simple — high error on both train and test (high bias).
  • Overfitting: too flexible — low train error, high test error (high variance).
  • Train to fit, validation to choose, test once to report.
  • More data, simpler models and regularization reduce overfitting.

Key papers

Essential

A few useful things to know about machine learning

Pedro Domingos · 2012 · Communications of the ACM

A short, practical essay on the lessons ML practitioners learn the hard way: generalization is what counts, data beats cleverness, and intuition fails in high dimensions.

How to read it: The best single reading for Chapter 3. Read it after the chapter; much of it will click.

~30 min readdoi:10.1145/2347736.2347755✓ verified 2026-09-26

Watch