Overfitting, the bias–variance trade-off, and the regularisation toolkit — how to tell which problem you have from the learning curves alone.
50 min1 interactive5 sources
A model that memorises the training set gets 100% on it and is worth nothing. The only number that has ever mattered is performance on data the model has never seen — everything in this lesson is machinery for buying that.
The intuition
Revising for an exam by memorising last year's paper. You'll ace last year's paper. Whether you pass this year's depends entirely on whether you learned the subject or the answer key — and the only way to find out is to sit a paper you haven't seen.
Unlearn this
That more model capacity always means more overfitting. That's the classical picture and it's incomplete: past the interpolation threshold, very large models often start generalising better again — the double-descent curve. It's why an LLM with more parameters than training tokens isn't automatically a memorisation machine.
01Underfitting, overfitting, and the gap that tells you which
Underfitting: the model is too simple, or hasn't trained long enough, to capture the real structure. Signature: training error is high, and validation error is about the same. The model is bad at data it has seen — no amount of regularisation will help, and adding data won't either.
Overfitting: the model has captured the noise as well as the signal. Signature: training error is low, validation error is much higher, and the gap widens as training continues. The model memorised.
Reading those two signatures off a learning curve is the diagnostic skill this lesson exists to build, because the remedies are opposite. High bias means add capacity, add features, train longer, reduce regularisation. High variance means add data, add regularisation, reduce capacity, stop earlier. Apply the wrong one and you make it worse with confidence.
Slide the degree from 1 to 12, then press resample a few times at each end. The wobble is variance.
02The bias–variance decomposition
For squared error, expected test error decomposes exactly into three parts: bias squared, variance, and irreducible noise. It's worth knowing formally because the interview question is usually 'define bias and variance', and definitions in terms of the decomposition are much sharper than hand-waving about complexity.
Bias is the error from wrong assumptions — how far the average model, over many training sets, is from the truth. A linear model fitting a curve has high bias no matter how much data you give it.
Variance is how much the model changes if you swap in a different training sample. A depth-30 decision tree has high variance: two random halves of the same data produce two very different trees.
Irreducible error is the noise in the labels themselves. No model beats it, and quoting a target accuracy above it is a red flag in a design review. Estimating human performance on the task is the usual way to bound it.
E[(y − f̂(x))²] = Bias[f̂]² + Var[f̂] + σ²
The exact decomposition for squared loss. σ² is irreducible — the noise floor no model crosses.
The classical picture: as capacity increases, bias falls and variance rises, so test error traces a U with a sweet spot in the middle. That picture is correct and useful for models of moderate size, and it's the answer expected in most interviews.
It also isn't the whole story. Push capacity past the interpolation threshold — the point where the model can fit the training data exactly — and test error frequently falls again, sometimes below the classical sweet spot. This is double descent, documented across model families, and it's part of why over-parameterised networks work at all.
The practical reading for 2026: for tabular and small-data problems, respect the U and tune capacity carefully. For deep networks at scale, capacity is rarely the lever you should reach for — data quantity, data quality and training duration usually dominate. Mentioning double descent as a nuance after giving the classical answer reads as current; leading with it instead of the classical answer reads as evasive.
More and better data. Boring, unglamorous, and almost always the strongest intervention available. Data augmentation is the cheap version: flips, crops and colour jitter for images, paraphrase and back-translation for text — generate new examples that preserve the label so the model learns the invariance you actually want.
Early stopping. Track validation loss, keep the checkpoint at its minimum, stop when it stops improving for a set patience. Free, effective, and it doubles as the answer to 'how many epochs?'
L2 (weight decay / ridge). Adds λΣw² to the loss, shrinking weights toward zero. Smaller weights mean a smoother function that's less able to contort around individual points. In AdamW this is applied directly to the weights rather than through the gradient, which is why AdamW behaves better than Adam with an L2 term.
L1 (lasso). Adds λΣ|w|. Because the penalty's gradient doesn't shrink as the weight approaches zero, it drives weights exactly to zero, producing sparse models and doing feature selection as a side effect. The 'why does L1 give sparsity and L2 not' question is common — answer geometrically: the L1 constraint region is a diamond whose corners lie on the axes, so the optimum tends to land on a corner where a coordinate is exactly zero.
Dropout. Randomly zero a fraction of activations each training step, so the network can't rely on any single unit and must build redundant representations. It's an approximate ensemble of exponentially many sub-networks. Disabled at inference, with activations scaled to compensate — forgetting model.eval() is a classic bug that makes evaluation look randomly worse than training.
Batch and layer normalisation. Primarily an optimisation aid — they stabilise training and let you use higher learning rates — but they carry a mild regularising effect too. Layer norm is standard in transformers because it doesn't depend on batch statistics, which matters for variable-length sequences and small batches.
Early stopping — the highest-return regulariser per line of code.
best, patience, wait = float("inf"), 5, 0
for epoch in range(max_epochs):
train_one_epoch(model, train_loader)
val = evaluate(model, val_loader) # NEVER the test set
if val < best - 1e-4:
best, wait = val, 0
torch.save(model.state_dict(), "best.pt") # keep the minimum, not the last
else:
wait += 1
if wait >= patience:
break
model.load_state_dict(torch.load("best.pt")) # roll back to the best checkpoint
Random search beats grid search for the same budget, and the reason is worth knowing: most hyperparameters barely matter, and grid search wastes its samples re-testing irrelevant dimensions while random search covers the important ones more finely. Bayesian optimisation beats both when each trial is expensive.
Search on validation, never on test. If you're going to search hard, use nested cross-validation or a genuinely untouched final holdout, because a big enough search will find a configuration that gets lucky on the validation set and you'll have overfitted your model selection.
And tune in order of impact: learning rate first, by an order of magnitude at a time, then batch size and schedule, then regularisation strength, then architecture. Architecture is usually the last thing that matters and the first thing people reach for.
The trap
'We tried 200 configurations and picked the best validation score' is model selection overfitting. With enough trials, some configuration wins by luck. Report the final number on a holdout you never searched against.
Error from wrong assumptions — how far the average model is from the truth. Underfitting.
Variance
Sensitivity to the particular training sample. Overfitting.
Irreducible error
Label noise. The floor no model crosses; estimate it before promising an accuracy target.
Double descent
Test error falling again past the interpolation threshold — why over-parameterised networks generalise.
L1 vs L2
L1 drives weights exactly to zero (sparsity, feature selection); L2 shrinks them smoothly (weight decay).
Dropout
Randomly zeroing activations in training so no unit is indispensable. An implicit ensemble; off at inference.
Early stopping
Keep the checkpoint at minimum validation loss. Cheapest effective regulariser there is.
The lab
Everything above, with the dials exposed. Break it deliberately — the failure modes are where the understanding is.
Try it
Fit the noise, or fit the signal?
Slide the degree from 1 to 12, then press resample a few times at each end. The wobble is variance.
What they actually ask
Fit & generalisation — the interview questions
QDefine the bias–variance trade-off.Answer it out loud first, then open this
Expected squared test error decomposes into bias² + variance + irreducible noise. Bias is error from over-simple assumptions — the model is wrong even on average. Variance is sensitivity to the specific training sample — the model changes a lot if you resample. Capacity trades one for the other, which classically gives a U-shaped test-error curve. The nuance for large networks is double descent: past the interpolation threshold error can fall again.
QHow do you know if you're overfitting?Answer it out loud first, then open this
The gap between training and validation performance, and its trend. If validation loss bottoms out and starts climbing while training loss keeps falling, that's the moment. I'd also check that the validation split is honest — with a time-ordered or grouped problem, a random split can hide overfitting completely by leaking near-duplicates across the boundary.
What they're listening for Adding 'and check the split is honest' is what a practitioner says. It's the failure that produces confident, wrong conclusions.
QDropout at inference time — what happens?Answer it out loud first, then open this
It's disabled. During training you zero a fraction p of activations and scale the survivors by 1/(1−p) so expected activation is unchanged; at inference all units are active with no scaling. Leaving dropout on at eval makes predictions noisy and metrics inconsistent — in PyTorch that's forgetting model.eval(). The exception is deliberate: keeping dropout on across many forward passes (MC dropout) as a cheap uncertainty estimate.
Before you move on
Recall beats re-reading, every time. Answer before you flip.
Fit & generalisation · self-test1 / 3
Training accuracy 99%, validation 71%. Diagnosis and three fixes?
Go to the primary sources
Where each claim above comes from. Open them alongside the lesson rather than after it — the papers are shorter than you think, and the figures usually carry the whole argument.
External links open in a new tab. Every URL was reachable when this page was written; links rot, so treat the list as a map rather than a guarantee.
Got it? Tick it off — progress saves on this device.
Fit the noise, or fit the signal?degree 3
Train RMSE
0.226
Held-out RMSE
0.231
Train 0.226, held-out 0.231. The gap is small and the held-out error is near its minimum — degree 6 is the sweet spot for this sample. The honest caveat: you found it by looking at the held-out score, so that score is now slightly optimistic. In a real project this set would be your validation split, and a separate untouched test set would give the number you report.
The grey dashed line is the truth the model never sees. Watch degree 1 refuse to bend, then degree 11 pass through every training point on its way to being useless.
Fit the noise, or fit the signal?degree 3
Train RMSE
0.226
Held-out RMSE
0.231
Train 0.226, held-out 0.231. The gap is small and the held-out error is near its minimum — degree 6 is the sweet spot for this sample. The honest caveat: you found it by looking at the held-out score, so that score is now slightly optimistic. In a real project this set would be your validation split, and a separate untouched test set would give the number you report.
The grey dashed line is the truth the model never sees. Watch degree 1 refuse to bend, then degree 11 pass through every training point on its way to being useless.