When Models Meet Data Overview
Chapters 2 through 7 built the mathematics: linear algebra, geometry, matrix decompositions, calculus, probability, optimization. Chapter 8 is where that mathematics meets a table of numbers.
The book states its own plan: “there are two different senses in which we use the phrase ‘machine learning algorithm’: training and prediction”, plus “the idea of selecting among different models”. Then it names the three sections that matter — empirical risk minimization (§8.2), maximum likelihood (§8.3), and probabilistic models (§8.4) — a graphical language for them (§8.5), and how to choose among them (§8.6).
The one question
Section titled “The one question”Everything in this chapter is an answer to a single problem:
You can measure how well a model does on the data you have. You care how well it does on data you do not have.
That is the gap between Equation 8.7’s empirical risk and Equation 8.10’s expected risk — one computable, one not. Regularization, priors, posteriors, cross-validation, the marginal likelihood, AIC and BIC are all attempts to say something about the second quantity using only the first.
Three flavours of learning
Section titled “Three flavours of learning”The chapter gives three answers, and the module measures where they agree and where they do not.
| §8.2 empirical risk | §8.3 likelihood / MAP | §8.4 Bayesian inference | |
|---|---|---|---|
| what you write down | a loss | a likelihood | a joint distribution |
| what you do to it | minimise | maximise | integrate |
| computational problem | optimization | optimization | integration |
| the answer | a point | a point | a distribution |
| needs a prior | no | MLE no, MAP yes | yes |
Two of the three turn out to be the same thing. §8.2.3’s penalty and §8.3.2’s prior produce identical estimates — measured to across six orders of magnitude — with . The third is genuinely different, and the difference is measurable: a nominal interval built from the full posterior achieves coverage in extrapolation where a plug-in interval achieves .
§8.1 Data, models and learning
Section titled “§8.1 Data, models and learning”Three components, each with a section of its own.
Data as vectors. Data is assumed tabular — rows are examples, columns are features — and in “a tidy format”. Getting there involves real choices: a categorical column can become or ; a postcode is “not just a string of characters but actually encodes an area in London”. The book is explicit that it does not discuss feature construction, which “depend[s] on domain expertise and require[s] careful engineering”.
Models. Two readings, and the chapter uses both. A model as a function — a predictor mapping inputs to outputs. A model as a probabilistic model — a distribution over what the data-generating process might produce. The second costs more and buys the thing the first cannot express: a statement about how confident the prediction is.
Learning. Three phases, and confusing them is the chapter’s central error mode:
| phase | what happens | what it must not touch |
|---|---|---|
| prediction / inference | run the fitted model on new inputs | — |
| training / parameter estimation | fit | the test set |
| hyperparameter tuning / model selection | choose , the degree, the architecture | the set you will report on |
The third row is why §8.6.1 nests two loops, and the cost of ignoring it is measurable: flat cross-validation reports better than chance on data containing no signal at all.
The pages
Section titled “The pages”| # | page | book section | the measured claim |
|---|---|---|---|
| 801 | Data, Models and Learning | §8.1 | the three phases, and what each may see |
| 802 | Empirical Risk Minimization | §8.2 | Eq 8.7 against Eq 8.10, and the loss you choose changes the winner |
| 803 | Regularization and Cross-Validation | §8.2.3–8.2.4 | the penalty that trades fit for , and how to pick it |
| 804 | Maximum Likelihood Estimation | §8.3.1 | the NLL is affine in the empirical risk — same minimiser, |
| 805 | MAP Estimation and Model Fitting | §8.3.2–8.3.4 | a prior is the penalty: , to |
| 806 | Probabilistic Modeling and Inference | §8.4 | Eq 8.23 holds coverage where the plug-in falls to |
| 807 | Directed Graphical Models | §8.5 | Example 8.9’s four d-separation claims, four for four |
| 808 | Model Selection | §8.6 | the automatic Occam’s razor, and the Jeffreys–Lindley paradox measured |
| 809 | Chapter 8 Worked Problems | — | eight problems, this module’s own |
| 810 | Chapter 8 Formula Sheet | — | every equation and every measured constant |
Four claims worth knowing before you start
Section titled “Four claims worth knowing before you start”1. Overfitting has the lowest training risk. Measured on Figure 8.8’s three cases: the overfitting model scores on training data — better than the model that actually generalises — and on held-out data, a ratio of . Underfitting announces itself; overfitting does not. The only training-side warning is the parameter norm, against .
2. A regularization penalty is a prior, exactly. Not analogously — identically. The largest disagreement between ridge regression and MAP across prior widths is . What the probabilistic vocabulary buys is not a different answer but a meaning for : a ratio of noise variance to prior variance, which immediately predicts that noisier data should be shrunk harder and more data less.
3. A point estimate cannot say “I don’t know.” Its predictive interval has width everywhere, because contains no reference to where you asked. Measured, that interval covers the truth of the time in far extrapolation while labelled . The full posterior covers .
4. Every model-selection number is hostage to something. Cross-validation is hostage to how hard you searched — better than chance on pure noise. The Bayes factor is hostage to the prior — with the data held fixed, its verdict flips from “decisively degree 9” to “decisively degree 1” as widens past . There is no criterion that is free.
Where it goes next
Section titled “Where it goes next”The book’s closing line for the chapter: the rest of this part shows “how the three different flavors of learning in Sections 8.2, 8.3, and 8.4 are applied to the four pillars of machine learning”.
| pillar | chapter | which flavour dominates |
|---|---|---|
| regression | 9 | all three — and the conjugate evidence §8.6.3 promised |
| dimensionality reduction | 10 | latent variables, §8.4.3, and Eq 8.28 |
| density estimation | 11 | mixtures, EM, and Eq 8.25’s marginalisation |
| classification | 12 | empirical risk with a different loss, §8.2 |
So Chapter 8 is not a detour before the applications. It is the vocabulary the remaining four chapters are written in — and Equation 8.28, the latent posterior given the parameters, is computed explicitly in both Chapter 10 and Chapter 11.
Recall card
Section titled “Recall card”- The chapter answers one question: you can measure performance on the data you have, and you care about the data you do not have. That is the gap between Equation 8.7’s empirical risk and Equation 8.10’s expected risk.
- Three flavours of learning: Section 8.2 minimises a loss, Section 8.3 maximises a likelihood, Section 8.4 integrates over a joint distribution. The first two solve an optimization problem and return a point; the third solves an integration problem and returns a distribution.
- Two of the three are the same estimator. A squared-norm penalty and a zero-mean Gaussian prior give identical answers with lambda equal to sigma squared over N tau squared, measured to 1.24e-14.
- Section 8.1’s three components: data as vectors, models as functions or as probability distributions, and learning as the search for parameters that generalise.
- Three phases of learning, and confusing them is the chapter’s central error: prediction, training, and hyperparameter tuning. The phase that chooses must not be the phase that reports.
- Overfitting has the lowest training risk of the three cases, and its expected risk is 748.8 times its training risk. Underfitting announces itself from training data alone; overfitting does not.
- A point estimate cannot express ignorance. Its interval has constant width everywhere, and measured, it covers the truth 17.96 percent of the time in far extrapolation while labelled 95 percent. The full posterior covers 94.98 percent.
- Every model-selection criterion is hostage to something — cross-validation to how hard you searched, the Bayes factor to the prior width. There is no free one.
- Section 8.5’s graphical language describes the joint distribution, and d-separation reads conditional independence off the picture without algebra.
- Chapter 8 is the vocabulary for Chapters 9 through 12 — regression, dimensionality reduction, density estimation and classification, the four pillars.
Start here: Data, Models and Learning
pch.coffeeTagline
pch.coffeeCtapch.feedbackHeading
pch.feedbackSubheading