1.1 — Linear regression as MLE under Gaussian noise
Goal: Show that least squares is exactly maximum likelihood under a Gaussian-noise model, and derive the normal equations as a stationarity condition.
1. Why this session exists
Linear regression is the simplest non-trivial model in this course, and the one we can take apart most rigorously. Three independent stories converge on it:
- Optimisation. Minimise (least squares).
- Probability. Maximise the likelihood of data under a Gaussian-noise observation model.
- Geometry. Orthogonally project onto the column space of .
This session shows that the first two are the same problem, with the same minimiser given in closed form by the normal equations. The geometric picture comes for free.
2. The probabilistic model
Fix a design matrix (rows are data points ) and a target vector . Assume
with unknown true parameter and known noise variance . Conditional on and ,
The likelihood of under parameter is the Gaussian density evaluated at the observed :
(The covariance is , which gives the diagonal Gaussian; the quadratic form in the exponent is the squared Euclidean norm.)
3. From MLE to least squares
The MLE estimator is . Logarithm is monotone, so
Taking the log,
The first term is constant in and drops out. The factor is positive, so maximising the log-likelihood is equivalent to minimising the residual sum of squares:
Least squares is MLE under Gaussian noise. This is the prototype: every standard loss we'll meet (BCE, multi-class CE, Huber, …) is the negative log-likelihood of some observation model.
4. The normal equations
Let . The factor of is purely cosmetic — it makes the gradient clean.
Expand:
Apply the matrix-calculus identities from 0.2 (numerator convention):
(The second uses when is symmetric.)
So
Setting this row vector to zero and transposing,
These are the normal equations: a linear system of equations in unknowns.
Existence and uniqueness. From 0.8 §4 we know , so is convex; any stationary point is a global minimum. If has full column rank, is invertible and
If is rank-deficient, the normal equations have a whole affine subspace of solutions; the minimum-norm solution is given by the Moore–Penrose pseudoinverse .
5. Geometric interpretation: projection
Let . The first normal equation says
i.e. the residual is orthogonal to every column of . So is the orthogonal projection of onto , with projector matrix
Two sanity checks: (idempotent) and (symmetric) — the defining properties of an orthogonal projector.
6. Quick computational note
Direct inversion of is numerically poor when is ill-conditioned (e.g. nearly-collinear features). In practice we either:
- Factorise via Cholesky and back-substitute.
- Compute a QR decomposition ; then — much better conditioned.
- Use the singular value decomposition ; then even when is rank-deficient.
Numerical linear algebra is its own course; we'll mention these techniques again when Hessian-based optimisers come up in Chapter 3.
7. Takeaways
- The Gaussian-noise model turns MLE into least squares: .
- The minimiser is unique when has full column rank: .
- Fitted values are the orthogonal projection of the targets onto the column space.
- This is the template: each loss function in the rest of the course will be the negative log-likelihood of some observation model.
(a) Derive the normal equations from scratch starting from . Show every step of the matrix differentiation.
(b) Prove that satisfies and . What is the trace of ? (Hint: it equals .)
(c) Suppose has linearly dependent columns. Show that still has a global minimum (in fact, infinitely many), and that the residual is unique even though is not.
(d) Bayesian twist. With a Gaussian prior instead of plain MLE, show that the MAP estimate is the ridge regression solution with . The regulariser is a Gaussian prior in disguise.
References
- [1]
Bishop, C. M. (2006). Pattern Recognition and Machine Learning. Springer. — Linear regression (1.1), logistic regression (1.2–1.3), softmax (1.7), MAP / Gaussian priors.
↩