Bayesian model selection
How to choose between models without holding out data: the evidence as a prediction of the data before seeing them, the automatic Occam's razor, Bayes factors and posterior model probabilities, the dependence on the prior width, empirical Bayes and full Bayesian inference.
Parameters and models: two levels of inference
The topic Conjugate priors and the exponential family gave us posteriors in closed form, but always inside one model chosen in advance. In practice several models fit the same data: a fair coin or a coin with an unknown bias, a polynomial of degree 1, 3 or 9, a narrow or a wide prior. This topic chooses among them with the tool we already have, Bayes' formula.
There are two levels. A parameter picks one member of a family. A model fixes the whole family: the likelihood , the prior and its hyperparameters. Linear and cubic regression are two models; two sets of cubic coefficients are two parameter values of one model.
Inside a model nothing is new:
The denominator, so far only a normalizer, now takes the lead. It is the evidence, or marginal likelihood, of the model:
The likelihood is averaged over the prior, not maximized.
One level up, the model is just another unknown, a discrete one. Bayes' formula again:
With equal prior probabilities of the models, the most probable model is the one with the largest evidence. Otherwise maximize the product .
Why not compare the fits? Because models are often nested. A cubic with zero leading coefficients is a straight line, so the best cubic fits at least as well as the best line, and the training error can only go down as the degree grows. A rule built on always votes for the biggest model.
Two practical remarks. In regression the inputs are taken as given, so the evidence is . For continuous data the evidence is a density value: it can exceed 1, and it changes with the units of . Compare evidences only for the same data in the same units.
The evidence as a prediction
What does the evidence measure? Feed the data in one point at a time and apply the product rule:
Each factor is a posterior predictive probability: what the model said about the next point after seeing the previous ones. The evidence is the model's track record of predicting the data before seeing them. A model cannot earn evidence by fitting the data afterwards; it has to have bet on them.
Take the coin from the topic The Bayesian approach. In model the probability of heads is unknown with a uniform prior . After heads in flips it predicts heads with probability
the rule that gave after three heads (H stands for heads). For the sequence H H H:
the same as the integral . Model , a fair coin, predicts every time and gets . On this sequence predicted better.
Two consequences:
- When the points are i.i.d. given , the order does not matter: the individual factors change, their product does not.
- is a sequential validation score. Each point is a test point for the model trained on the points before it; nothing is held out and nothing is used twice.
The automatic Occam's razor
Multiply out the predictive factors for any sequence with heads in flips and you get
There are such sequences, so the probability of the count is : before the data, finds every count from to equally likely. The fair coin gives , a bump around .
Now the key fact. For every the likelihood sums to one over all possible datasets, and therefore so does the evidence:
The evidence is a fixed budget of probability, spread over the datasets the model can produce. A flexible model that can explain many datasets must spread it thin. A rigid model puts its budget on a few datasets and wins big if one of them shows up. Nobody added a penalty for complexity; it follows from normalization. This is the automatic Occam's razor.
With , model gives each of the nine counts . The fair coin gives to and only to or . Where the fair coin placed its bet, it beats the flexible model; far from it, it loses.
The budget picture has a formula too. When the posterior is a narrow peak of width inside a prior of width ,
The first factor is the best fit. The second, the Occam factor, is the fraction of the prior range that survives the data; the topic The Laplace approximation and Bayesian classification derives it. For 7 heads in 8 flips, and the best fit is , about 12.6 times the fair coin's . With and , the Occam factor is about . The approximate evidence is close to the exact . Flexibility bought a 12.6 times better fit and cost a factor of about 3.4.
The Bayes factor
To compare two models, divide their posteriors; the common denominator cancels:
Posterior odds are the Bayes factor times the prior odds. The Bayes factor is what the data say; the prior odds are what you believed before them.
For 7 heads in 8 flips, . It makes no difference whether the data are the sequence or only the count: the binomial coefficient multiplies both evidences and cancels. With equal prior odds, .
A rough scale (Jeffreys; Kass and Raftery): from 1 to 3 is barely worth mentioning, 3 to 20 is positive, 20 to 150 strong, above 150 very strong. Our 3.56 is just positive.
Unlike a p-value, a Bayes factor can support the simpler model. But it does so slowly. When exactly half of the flips are heads, is at , at and at . It grows like , because the flexible model's Occam factor shrinks like . Evidence against a wrong simple model, by contrast, grows exponentially in . A flexible model is never refuted by data it can also explain; it is only out-predicted.
The evidence remembers the prior width
Inside one model the prior fades as data accumulate. The evidence never forgets it: the Occam factor is the posterior width divided by the prior width, so a prior twice as broad halves the evidence for each parameter it governs.
The running example from the topic Conjugate priors and the exponential family, the Normal mean with known variance. A kitchen scale may have an offset . We weigh a reference weight times; the noise has g, and the readings minus the true weight average to g. Model : the scale is calibrated, . Model : , with the prior variance named as in that topic.
Since is sufficient, with . The factor does not involve , is the same in both models and cancels from the Bayes factor. Under , is plus independent noise, so the variances add:
With this is : mild support for an offset.
Now let grow. The exponential stays below , while the square root falls like . As the calibrated model wins whatever is: this is the Jeffreys–Lindley paradox. Meanwhile the posterior of under tends to , which is perfectly sensible. The posterior is fine; the evidence is ruined.
Improper priors make it worse. A "flat prior on the whole line" is not a distribution. The constant cancels from the posterior but multiplies the evidence, so the Bayes factor can be made anything. The practical rules: use proper priors on the scale of the problem, report how the conclusion depends on the prior, and when it flips, trust held-out likelihood or cross-validation, which depend on the prior only through the posterior.
Evidence maximization: empirical Bayes
If the evidence is so sensitive to , why not let the data choose it? Treat the hyperparameter as a knob of the model and pick the value with the largest evidence:
This is evidence maximization, also called empirical Bayes or type-II maximum likelihood: is integrated out, is maximized. After that we use the ordinary conjugate posterior and its predictive distribution.
For the kitchen scale the integral is already done. Up to terms that do not depend on ,
One derivative with respect to and the constraint finish the job; you will do it in the check below.
Why integrate out instead of maximizing jointly over and ? Because the joint density has no maximum. Put and send : the prior becomes an ever taller spike, , while the likelihood stays fixed. Integration replaces the height of the spike by its mass, which is always 1.
Empirical Bayes is the standard way to set the precisions and in Bayesian linear regression and a separate precision per weight in the relevance vector machine. It works well with few hyperparameters and plenty of data; with one hyperparameter per weight it can overfit.
MAP, empirical and full Bayes
We now have three ways to treat the unknowns, from the least to the most Bayesian:
| Approach | Integrated out | Maximized | Example |
|---|---|---|---|
| MAP / MLE | nothing | , with fixed | ridge regression with a fixed penalty |
| Empirical Bayes | the previous block; the RVM | ||
| Full Bayes | and | nothing | a hyperprior, then sampling or VI |
Full Bayes gives the hyperparameter its own prior , a hyperprior, and works with the joint posterior
Empirical Bayes is the shortcut: it is close to full Bayes when the evidence is sharply peaked in a few hyperparameters. It uses the data twice, first to pick and then to fit , and it treats the chosen as certain. A side effect in the scale example: a tuned can never lose to , because reproduces .
The same logic applies to the models themselves. If the model is unknown, you need not pick one; average the predictions with the posterior weights, Bayesian model averaging:
For 7 heads in 8 with equal prior odds, ; predicts heads with and with , so the averaged prediction is .
Two limits to keep in mind. The evidence ranks models only within the set of models and priors you wrote down; it does not promise the best test error, especially when none of the models is true. And it is an integral: exact for conjugate and linear-Gaussian models, otherwise approximated by Laplace, variational bounds or sampling, which come later in the course.
Next comes the workhorse of the course, the topic Bayesian linear regression: a Gaussian prior on the weights with precision and Gaussian noise with precision . Its evidence is again a Gaussian integral, and choosing and is exactly the evidence maximization of this topic, with in the role of .
Check your understanding
The same questions as in Pulse. Answers are shared between modes.
Answers are saved on the server and tied to this browser until you sign in.