Advanced Mathematics

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 λ∥w⃗∥2\lambda\|\vec w\|^2 to the loss (ridge, or weight decay), which shrinks the weights. Choosing λ\lambda, 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 λ∥w⃗∥2\lambda\|\vec w\|^2 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 λ\lambda 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 y^=wx\hat y = wx (no intercept) to the points (1,1)(1, 1) and (2,3)(2, 3). Find ww by plain least squares, then by ridge regression minimising ∑(yi−wxi)2+λw2\sum(y_i - wx_i)^2 + \lambda w^2 with λ=2\lambda = 2.
Show the worked answer
Setting the derivative to zero: −2∑xi(yi−wxi)+2λw=0-2\sum x_i(y_i - wx_i) + 2\lambda w = 0, so w=∑xiyi∑xi2+λw = \frac{\sum x_i y_i}{\sum x_i^2 + \lambda}. Here ∑xiyi=1+6=7\sum x_i y_i = 1 + 6 = 7 and ∑xi2=5\sum x_i^2 = 5. Least squares (λ=0\lambda = 0): w=7/5=1.4w = 7/5 = 1.4. Ridge with λ=2\lambda = 2: w=7/7=1w = 7/7 = 1. The penalty shrinks the slope towards zero.

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.

On the way to

Recommended