Skip to content

Linear Regression Overview

Chapter 8 built a vocabulary and named three flavours of learning. Chapter 9 applies all three to one problem, in order, and the problem is the first of the book’s four pillars: “we aim to find a function ff that maps inputs xRD\mathbf{x} \in \mathbb{R}^D to corresponding function values f(x)Rf(\mathbf{x}) \in \mathbb{R}.”

The book’s framing: “we will apply the mathematical concepts from Chapters 2, 5, 6, and 7 to solve linear regression (curve fitting) problems” — and the task is “to find a function that not only models the training data, but generalizes well.”

§9.2.1 maximum likelihood§9.2.3 MAP§9.3 Bayesian
what you write downa likelihoodlikelihood ×\times priorthe same, and you integrate
the answera pointa pointa distribution
exists when K>NK > Nnoyesyes
predictive intervalwidth σ\sigma, everywherewidth σ\sigma, everywherewidens off the data
measured coverage0.74190.7419 / 0.11120.1112the same0.9487\mathbf{0.9487} / 0.9499\mathbf{0.9499}

Two of the three give the same prediction curve. Measured to 8.4×10148.4\times10^{-14}: MAP and the Bayesian posterior mean are one curve, because for a Gaussian the mode is the mean. So the case for §9.3 is not about the line — it is entirely about the shading, and the shading is what turns 0.11120.1112 into 0.94990.9499.

Why this chapter is where the measuring pays off

Section titled “Why this chapter is where the measuring pays off”

Everything here has a closed form, so every claim can be checked exactly rather than approximately. Four things the chapter states, and what measuring them turned up:

The book gives two different λ\lambda for one correspondence. Equation 9.33’s text says λ=1/(2b2)\lambda = 1/(2b^2) and Equation 9.34’s says λ=σ2/b2\lambda = \sigma^2/b^2. Measured across five settings, only the second reproduces Equation 9.31 — and Chapter 8 supplies a third, σ2/(Nτ2)\sigma^2/(N\tau^2), for its own normalisation. All three are internally correct. A λ\lambda is meaningless without the objective it belongs to.

Equation 9.22’s noise estimate is biased by exactly (NK)/N(N-K)/N. The book states it without caveat. Measured at N=10N = 10, K=5K = 5 — Example 9.5’s own setting — it returns half the true variance, and §9.4’s geometry explains why: tr(IP)=NK\mathrm{tr}(\mathbf{I}-P) = N-K, so the residual never occupies all NN dimensions.

Example 9.7’s prior is far wider than its figure can show. With the book’s own N(0,14I)\mathcal{N}(\mathbf{0}, \tfrac14\mathbf{I}) and degree-5 monomials, the 95%95\% band is 3125.593125.59 units wide at x=5x = 5 — on axes drawn from 4-4 to 44. It fits inside them at 4848 of the 200200 plotted inputs. The shape the figure draws is right; the scale is the part worth measuring.

Equation 9.64 is a derivation, not an implementation. It inverts an N×NN\times N matrix for a model with KK parameters. Woodbury gives the same number through a K×KK\times K one — 4341×4341\times faster at N=4000N = 4000 — and its determinant factor is SN1\mathbf{S}_N^{-1}, already computed by Theorem 9.1.

#pagebook sectionthe measured claim
901Problem Formulation§9.1–9.2the likelihood integrates to 1/x1/\lvert x\rvert over θ\boldsymbol\theta
902Maximum Likelihood Estimation for Linear Regression§9.2.1Eq 9.22 is biased by exactly (NK)/N(N-K)/N
903Overfitting in Linear Regression§9.2.2the training error never rises — nine steps, zero increases
904MAP Estimation and Regularization§9.2.3–9.2.4only λ=σ2/b2\lambda = \sigma^2/b^2 reproduces Eq 9.31
905Bayesian Linear Regression§9.3.1–9.3.2the prior’s 95%95\% band is 3125.593125.59 wide at x=5x = 5
906The Parameter Posterior§9.3.3precisions add, so the update runs online to 4.1×10124.1\times10^{-12}
907Posterior Predictions§9.3.4SN\mathbf{S}_N is unchanged by shuffling the targets
908Computing the Marginal Likelihood§9.3.5the evidence picks the same degree a test set does
909Maximum Likelihood as Orthogonal Projection§9.4tr(P)=K\mathrm{tr}(P) = K, which explains page 902’s bias
910Chapter 9 Worked Problemseight problems, this module’s own
911Chapter 9 Formula Sheetevery equation and every measured constant

One number appears on three pages by three different routes, and noticing that is most of understanding Bayes’ theorem in this setting:

where it appearspagevalue
the constant offset making Theorem 9.1 consistent906+30.453407+30.453407
the training targets’ density under the prior predictive90730.453407-30.453407
Equation 9.64 evaluated directly90830.453407-30.453407

It is logp(YX)\log p(\mathcal{Y}\mid\mathcal{X}) — the normaliser page 901 found missing when the likelihood turned out to integrate to 1/x1/\lvert x\rvert rather than 11. Maximum likelihood can ignore it because an argmax ignores scale. Everything else in the chapter needs it, and §8.6 needs it to compare models at all.

Chapter 8 established the ideas. This chapter supplies the closed forms — and three results that only appear once you have them:

Precisions add, so learning can be sequential. Equation 9.43b is a sum over observations, so feeding the data in any order or grouping gives the same posterior. Measured over 500500 points fed one at a time: 6.8×10156.8\times10^{-15} from the batch answer, in O(K2)O(K^2) memory, with the design matrix never assembled. The book computes it in one shot; nothing requires that.

The error bars are known before the experiment. SN\mathbf{S}_N contains no y\mathbf{y} — measured, shuffling the targets changes it by exactly zero. So you can choose where to measure to minimise the interval where it matters: a clustered design gives a worst 95%95\% half-width of 286.95286.95 against 0.4740.474 for a spread one, a factor of 605605, decided in advance. The same property is why the shading does not widen when the model fits badly.

The estimator is a projection, and that explains two earlier puzzles. tr(P)=K\mathrm{tr}(P) = K gives Equation 9.22’s bias exactly; and since a projection depends on the subspace rather than the basis, page 902’s conditioning catastrophe (κ=2.2×1026\kappa = 2.2\times10^{26} for monomials against 1.0000001.000000 for an orthonormal basis, same fit to 4.8×10134.8\times10^{-13}) was always a coordinate problem.

§9.5 points three ways, and all three are visible in what the chapter already computed:

pointerand where it already appeared
generalized linear models — Eq 9.72, a deep network as a composition of themChapter 8’s §8.3.4, and the note that maximum likelihood becomes non-convex
Gaussian processes — a distribution placed directly on functionspage 905 measured the induced kernel ϕ(xa)S0ϕ(xb)\phi(x_a)^\top\mathbf{S}_0\phi(x_b), including a 204.75-204.75
sparsity priors — Laplace, i.e. LASSOpage 904 measured ridge producing zero exact zeros at any λ\lambda against LASSO’s 2727 of 3030

And the remaining pillars: Chapter 10 applies the same machinery to dimensionality reduction, Chapter 11 to density estimation, Chapter 12 to classification.

  • Chapter 9 solves one problem three times — maximum likelihood, MAP, and full Bayesian inference — applying Chapter 8’s three flavours of learning to the first of the four pillars.
  • Two of the three give the same prediction curve, to 8.4e-14, because for a Gaussian the mode is the mean. The case for Section 9.3 is entirely about the interval.
  • And the interval is what turns 0.1112 into 0.9499 in measured coverage just outside the data.
  • The book names two different lambdas for one correspondence, and Chapter 8 supplies a third. All are internally correct; a lambda is meaningless without its objective.
  • Equation 9.22’s noise estimate is biased by exactly (N-K)/N, returning half the truth in Example 9.5’s own setting. Section 9.4 explains why: the trace of I minus P is N minus K.
  • Example 9.7’s prior implies a 95 percent band 3125.59 units wide at x = 5, on a figure whose axes run from minus four to four.
  • Equation 9.64 inverts an N-by-N matrix for a K-parameter model. Woodbury gives the same number 4341 times faster, reusing the posterior precision Theorem 9.1 already computed.
  • One number appears on three pages by three routes: 30.453407, the log marginal likelihood — the normaliser page 901 found missing.
  • Precisions add, so the posterior update runs online in fixed memory, matching the batch answer to 6.8e-15 over 500 points.
  • The error bars never see the targets, so they can be minimised during experimental design — a factor of 605 between a clustered and a spread layout — and they cannot warn you that the model is wrong.
  • The estimator is an orthogonal projection, which explains both the noise-variance bias and why the monomial basis’s conditioning disaster was avoidable.
  • Section 9.5 points to generalized linear models, Gaussian processes and sparsity priors, and the chapter has already computed a piece of each.

Start here: Problem Formulation

pch.coffeeTagline

pch.coffeeCta

pch.feedbackHeading

pch.feedbackSubheading