Overfitting and Regularisation
A model that fits its training data too closely does worse on new data; regularisation trades a little training fit for better generalisation.
Needs a step first: 33
A flexible enough model can pass through every training point, noise included, and then predict badly, so we judge a model on data it has not seen: a held-out validation set, or cross-validation. Regularisation pulls towards simpler fits, for example adding to the loss (ridge, or weight decay), which shrinks the weights. Choosing , the model size or when to stop training is a bias–variance trade-off, checked against validation error. The same discipline governs training deep networks, where dropout and early stopping play this role.
Where it shows up: Weight decay, dropout and early stopping in training deep networks are all regularisation, judged on a validation set.
How to hold it: In your head
See why a model judged only on its training data flatters itself, and why a held-out set and a penalty such as keep it honest.
What knowing it looks like
- Recognise overfitting from training and validation loss curves.
- Solve a small ridge regression by hand and see the weight shrink as grows.
- Explain why a held-out set must not be used to choose the model and then also to report its accuracy.
Test yourself
Fit (no intercept) to the points and . Find by plain least squares, then by ridge regression minimising with .
Show the worked answer
Needs a step first: 33
Learn it with an AI
Copy this prompt into any AI assistant. It will take you through step by step at your level and finish with the test above.
Be my maths tutor. I'm learning "Overfitting and Regularisation" (Undergraduate II tier): A model that fits its training data too closely does worse on new data; regularisation trades a little training fit for better generalisation. I already know: Linear Regression as Learning, Confidence Intervals and Hypothesis Tests. Teach it Socratically: first ask what I already know; then explain the core idea with one concrete example and why it's true; then give me three problems, one at a time, easy to hard. Wait for my answer, check every step, and point out mistakes without giving the answer away. Finish by testing me with this: Fit $\hat y = wx$ (no intercept) to the points $(1, 1)$ and $(2, 3)$. Find $w$ by plain least squares, then by ridge regression minimising $\sum(y_i - wx_i)^2 + \lambda w^2$ with $\lambda = 2$. Use LaTeX for formulas. When you say where it's used later (machine learning, quantum mechanics), be specific.
Needs first
- Linear Regression as LearningFitting by choosing the parameters that minimise the mean squared error: the simplest model that learns from data.Undergraduate II · Machine Learning
- Confidence Intervals and Hypothesis TestsTurning a sample into a statement about the whole population: a range of plausible values, or a test of a claim.Undergraduate I · Probability & Statistics
Leads to
On the way to
Recommended
- Neural Networks: Zero to HeroAndrej Karpathy · VideosFree lectures that build backpropagation, a language model and a small GPT from scratch in Python, explaining every line.
- Understanding Deep LearningSimon J. D. Prince (MIT Press) · BookA clear, well-illustrated 2023 textbook covering networks, training, transformers, diffusion models and reinforcement learning, free as a PDF with Python notebooks.
- 动手学深度学习阿斯顿·张、李沐等 · Book · 中文The Chinese edition of Dive into Deep Learning: a free textbook in which every model, from linear regression to transformers, runs as code beside the maths.
- 跟李沐学AI李沐 · Videos · 中文Mu Li's own Bilibili channel: the video course for Dive into Deep Learning and paragraph-by-paragraph readings of key papers, including the Transformer paper.