CS 460G Midterm Hub / Lectures / Week 6 Lecture 3
Week 6 · Lecture 3

Regularisation

Inductive bias, bias-variance, under/overfitting, L1 vs L2, elastic net, dropout.

short answermath

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.

Inductive bias defined
Inductive bias defined · slide 23

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
Hypothesis space must be large enough but small enough
Hypothesis space must be large enough but small enough · slide 26

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.
Bias and variance defined by repeated retraining
Bias and variance defined by repeated retraining · slide 29

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

UnderfittingRight fitOverfitting
Modeltoo simplejust righttoo complex
Training errorhighslightly below testvery low
Test errorhigh, close to trainclose to trainmuch higher than train
Dominant termhigh biasbalancedhigh variance
Example model$w_0+w_1x$$w_0+w_1x+w_2x^2$$w_0+\dots+w_4x^4$
Underfitting — high bias
Underfitting — high bias · slide 30
Overfitting — high variance
Overfitting — high variance · slide 32

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:

ProblemRemedies
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)
Remedies for high variance
Remedies for high variance · slide 35
Remedies for high bias
Remedies for high bias · slide 37

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$.

What regularisation does
What regularisation does · slide 39

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}}$$

Data loss plus regularisation term
Data loss plus regularisation term · slide 40

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$
The three norms
The three norms · slide 38

L1 versus L2 — the table to memorise

L1 / LassoL2 / Ridge
Penalty$\lambda\sum_i \lvert w_i\rvert$$\lambda\sum_i w_i^2$
Also calledL1 shrinkageL2 shrinkage, weight decay
Effect on weightsdrives some exactly to zero → sparseshrinks all smoothly toward zero, rarely exactly zero
Resultfeature selection falls out of the fitall features retained, small
Geometrydiamond constraint → optimum hits a cornercircle constraint → tangency, not a corner
Collinearitypicks one of a correlated pair arbitrarilydistributes weight across correlated features
Closed formnone (needs coordinate descent / LARS)yes — $\hat w=(A^TA+\lambda I)^{-1}A^Tb$
Good whenfew features mattermany features all matter a little
L1 / lasso
L1 / lasso · slide 44
L2 / ridge
L2 / ridge · slide 43

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

Elastic net
Elastic net · slide 45

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.

Regularisation intuition — do not fit the noise
Regularisation intuition — do not fit the noise · slide 41

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.
Dropout
Dropout · slide 47

"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.