Regularisation
Inductive bias, bias-variance, under/overfitting, L1 vs L2, elastic net, dropout.
The deck that answers "regularisation", "L1 vs L2", "overfitting vs underfitting" and the bias-variance trade-off, in one place.
Inductive bias
> Anything that makes a learning algorithm learn one solution or interpretation over another. Assumptions serve as the foundation for learning and generalisation.

The hypothesis-space question is the important one: how large should $\mathcal{H}$ be?
- Large enough to contain a solution
- Small enough to ensure reliable generalisation

Two types: restriction bias (limits the set of hypotheses considered — e.g. "only linear functions") and preference bias (favours some hypotheses over others — e.g. "among linear fits, prefer the smallest weights", which is exactly what regularisation does).
Bias and variance
- Bias — how far off the model's average predictions are from the correct values.
- Variance — the variability in the model's predictions as a result of the choice of training set.

The operational test the slide gives: rebuild the model on many different training sets. The systematic offset that survives is bias; the spread across rebuilds is variance.
$$E\big[(y-\hat f(x))^2\big] = \underbrace{\text{Bias}[\hat f(x)]^2}_{\text{systematic}} + \underbrace{\text{Var}[\hat f(x)]}_{\text{from the sample}} + \underbrace{\sigma^2}_{\text{irreducible noise}}$$
Underfitting, right fit, overfitting
| Underfitting | Right fit | Overfitting | |
|---|---|---|---|
| Model | too simple | just right | too complex |
| Training error | high | slightly below test | very low |
| Test error | high, close to train | close to train | much higher than train |
| Dominant term | high bias | balanced | high variance |
| Example model | $w_0+w_1x$ | $w_0+w_1x+w_2x^2$ | $w_0+\dots+w_4x^4$ |


The single diagnostic sentence: overfitting is a large gap between training and test error; underfitting is a large training error. If both are high, you are underfitting. If train is low and test is high, you are overfitting.
Remedies, straight from the deck:
| Problem | Remedies |
|---|---|
| High variance (overfitting) | add more training data; reduce model complexity; bagging (model ensemble) |
| High bias (underfitting) | add more features; use a more complex model; boosting (model ensemble) |


Note how bagging appears under variance and boosting under bias — that mapping is itself an exam question, and it follows directly from what each ensemble does: bagging averages independent high-variance models; boosting sequentially reduces the bias of weak learners.
Regularisation
> The process of making the model fit the training data less well in order to improve generalisation. It penalises large values of $w$.

A new term is added to the original loss:
$$J(w) = \underbrace{L_{\text{data}}(w)}_{\text{predictions must match data}} + \lambda\underbrace{\Omega(w)}_{\text{prevent fitting too well}}$$

The named norms:
- $\ell_0$ — number of non-zero coefficients (sparsest, but combinatorial and not differentiable)
- $\ell_1$ (lasso) — $\sum_{i=1}^{d}|w_i|$
- $\ell_2$ (ridge) — $\sum_{i=1}^{d}w_i^2$

L1 versus L2 — the table to memorise
| L1 / Lasso | L2 / Ridge | |
|---|---|---|
| Penalty | $\lambda\sum_i \lvert w_i\rvert$ | $\lambda\sum_i w_i^2$ |
| Also called | L1 shrinkage | L2 shrinkage, weight decay |
| Effect on weights | drives some exactly to zero → sparse | shrinks all smoothly toward zero, rarely exactly zero |
| Result | feature selection falls out of the fit | all features retained, small |
| Geometry | diamond constraint → optimum hits a corner | circle constraint → tangency, not a corner |
| Collinearity | picks one of a correlated pair arbitrarily | distributes weight across correlated features |
| Closed form | none (needs coordinate descent / LARS) | yes — $\hat w=(A^TA+\lambda I)^{-1}A^Tb$ |
| Good when | few features matter | many features all matter a little |


Elastic net combines both: $\lambda_1\sum|w_i| + \lambda_2\sum w_i^2$.

A regularised model can have worse training error and better test error. That is the entire point, and an exam answer that says "regularisation improves accuracy" without saying "improves generalisation at the cost of training fit" is imprecise. The notebook demonstrates it directly: ridge $\alpha=0.05$ moves MSE from 2537 to 2508 on the test split — a small improvement, because the improvement is bounded by how much the unregularised model was overfitting.
The intuition slide is worth a sentence in any answer: the fitted curve is pushed against fitting the data too well, so the noise is not fitted, only the signal.

Beyond the norms
- Max-norm — clamp every neuron's weight vector so that $\|w\|_2 < c$; an absolute upper bound rather than a penalty.
- Dropout — during training each neuron is kept active with probability $p$ (a hyperparameter). At test time you use the full network, which approximates averaging exponentially many thinned subnetworks.

"What is regularisation? Compare L1 and L2." Define it as adding a penalty $\Omega(w)$ to the loss so the optimiser prefers smaller weights, trading a little bias for a large reduction in variance. Then the comparison: L1 penalises the absolute value and produces exact zeros, so it performs feature selection and is the right choice when you suspect most features are irrelevant; L2 penalises the square, shrinks smoothly without zeroing, handles correlated features gracefully and has the closed form $(A^TA+\lambda I)^{-1}A^Tb$ that also fixes the non-invertibility of $A^TA$ when $d>N$. Close with the geometric reason: the L1 ball has corners on the axes, so the level sets of the loss touch it at a corner where some coordinates are zero; the L2 ball is smooth, so tangency happens at a generic point.




































