Concept · Chapter 3: Machine Learning
Generalization, Overfitting and Underfitting
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.
You should understand first
- The Turing Test
- Symbolic AI
- Logic and Rules
- Expert Systems
- Knowledge Representation
- The Knowledge-Acquisition Bottleneck
- From Rules to Learning
- Supervised, Unsupervised and Self-Supervised Learning
- Vectors
- Features, Labels and Tasks
- Loss Functions
- Derivatives and Gradients
- Gradient Descent
- Linear Regression
- Probability and Distributions
- Expected Value and Variance
- Sampling and Uncertainty
- Generalization, Overfitting and Underfitting
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
Fit curves of increasing complexity to 12 noisy points. Training error keeps falling; error on new data falls, then soars. Then add regularization.
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:
The discipline: train, validation, test
Train set
Fit the model's parameters.Validation set
Choose everything else — model type, degree, regularization strength, when to stop. (With little data, rotate this role with k-fold cross-validation.)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
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.
Watch
StatQuest with Josh Starmer
Machine Learning Fundamentals: Bias and Variance
Seven minutes on the most important trade-off in machine learning.
StatQuest with Josh Starmer
Machine Learning Fundamentals: Cross Validation
Why you never test on your training data, and how to use limited data well.