The marginal likelihood is the probability of the observed data under a model, computed by integrating the likelihood over the prior distribution of the model parameters. Written as p(D | M) = ∫ p(D | θ, M) p(θ | M) dθ, it is also called the model evidence or Bayesian evidence, and it is the normalizing constant in the denominator of Bayes’ theorem.
In probabilistic models, the marginal likelihood plays two roles. It turns an unnormalized posterior into a proper posterior distribution, and it scores how well an entire model, including its prior, explains the data. That second role makes it the foundation of Bayesian model comparison, Bayes factors and the tuning of hyperparameters in methods such as Gaussian processes.
How the marginal likelihood is defined
The marginal likelihood averages the likelihood over all parameter values, weighting each value by its prior probability. Because the parameters are integrated out, the result depends only on the data and the model specification, which is why the quantity is called marginal.
Bayes’ theorem places it in context: the posterior equals likelihood times prior, divided by the evidence. For inference about parameters within a single model the evidence is a constant and can be ignored, which is why MCMC methods sample the posterior without computing it. Comparing different models, however, requires the evidence explicitly.
| Quantity | Notation | Role |
|---|---|---|
| Prior | p(θ | M) | Beliefs about parameters before the data |
| Likelihood | p(D | θ, M) | Fit of specific parameter values to the data |
| Posterior | p(θ | D, M) | Updated beliefs about parameters |
| Marginal likelihood | p(D | M) | Support for the whole model, normalizing constant |
Why the marginal likelihood penalizes complexity
The evidence contains a built-in Occam’s razor. A flexible model spreads its prior probability over many possible data sets, so it assigns relatively little probability to any single data set. A simpler model that still explains the observed data concentrates its probability and therefore earns higher evidence.
This effect is often summarized as best-fit likelihood times an Occam factor, where the Occam factor is roughly the ratio of posterior volume to prior volume. Unlike training error, the marginal likelihood does not automatically favor the most complex model, which is why it supports model selection without a separate validation set.
The penalty, however, is sensitive to the prior. Making a prior very broad lowers the evidence even when the posterior barely changes, a behavior related to the Jeffreys-Lindley paradox. Improper priors make the evidence undefined, so evidence-based comparisons demand carefully chosen, proper priors.
Methods for computing or approximating it
Exact evaluation is possible only for conjugate models and Gaussian processes with Gaussian noise. In most other models the integral is high-dimensional and has no closed form, so practitioners rely on approximations with different accuracy and cost.
| Method | Principle | Typical accuracy | Main limitation |
|---|---|---|---|
| Analytic solution | Closed-form integral | Exact | Only conjugate or Gaussian models |
| Laplace approximation | Gaussian fit around the posterior mode | Good for unimodal posteriors | Poor for skewed or multimodal shapes |
| BIC | Large-sample asymptotic of Laplace | Rough | Ignores the prior, needs many data points |
| Evidence lower bound | Variational bound on log evidence | Lower bound only | Gap depends on the variational family |
| Importance sampling | Weighted samples from a proposal | Good with a good proposal | High variance in high dimensions |
| Nested sampling | Integration over likelihood contours | Good for moderate dimensions | Computationally expensive |
| Thermodynamic integration | Path between prior and posterior | High | Requires many MCMC runs |
The harmonic mean estimator, which reuses posterior samples, is easy to compute but notoriously unstable and can have infinite variance. Most practitioners advise against it.
Bayes factors and model comparison
The ratio of the evidence of two models is the Bayes factor, which updates prior odds between models into posterior odds. Analysts usually report its logarithm and interpret it on conventional evidence scales such as the one proposed by Kass and Raftery.
| Bayes factor in favor of a model | Natural log | Strength of evidence |
|---|---|---|
| 1 to 3 | 0 to 1.1 | Barely worth mentioning |
| 3 to 20 | 1.1 to 3 | Positive |
| 20 to 150 | 3 to 5 | Strong |
| Above 150 | Above 5 | Very strong |
These thresholds are conventions, not laws. A Bayes factor compares only the models under consideration, so a high value does not prove that either model is correct, only that one explains the data better relative to the other.
Use in machine learning
In machine learning the marginal likelihood is used mainly for type II maximum likelihood, also called empirical Bayes: hyperparameters are chosen by maximizing the evidence rather than by cross-validation. Gaussian process regression is the classic case, where kernel length scales and noise variance are fitted this way.
- Variational autoencoders maximize the evidence lower bound as a training objective for the log marginal likelihood.
- Bayesian neural networks use evidence approximations, often via the Laplace method, to select priors and architectures.
- Mixture models and topic models use it to choose the number of components or topics.
- Probabilistic programming systems offer evidence estimators for comparing alternative model structures.
Limitations and common mistakes
The evidence is a powerful but fragile criterion. Its value reflects the prior as much as the likelihood, and numerical estimates can be badly biased. The most frequent problems are summarized below.
| Mistake | Consequence | Remedy |
|---|---|---|
| Vague or improper priors | Evidence undefined or arbitrarily low | Use proper, justified priors |
| Harmonic mean estimates | Unstable, misleading values | Use nested or bridge sampling |
| Treating ELBO as evidence | Biased model ranking | Compare bounds with caution |
| Overfitting hyperparameters | Overconfident predictions | Check with held-out predictive performance |
When predictive accuracy matters more than model plausibility, criteria such as cross-validation or WAIC are often more robust, because they measure how well the posterior predicts new data rather than how well the prior anticipated the observed data.
The short version
The marginal likelihood tells you how well a whole model predicted the data before seeing it. It does not judge one best setting of the model. It averages over every setting the model considered plausible.
Imagine two forecasters. One makes a narrow, confident prediction. The other spreads bets over many outcomes. If the narrow prediction comes true, that forecaster deserves more credit. The marginal likelihood gives credit the same way. Models that make sharp, correct predictions win. Vague models that could explain anything lose points.
Where it makes a difference
A data scientist at an energy utility forecasts hourly electricity demand with Gaussian process regression. She must choose between a kernel with only a smooth trend and one that adds a 24-hour periodic component. Cross-validation on time series is awkward, so she compares the log marginal likelihood of both models after fitting their hyperparameters.
On two years of hourly data, the periodic kernel achieves a log evidence about 40 nats higher, an overwhelming Bayes factor. The fitted periodic length scale matches the daily cycle, and a held-out month confirms the choice: the mean absolute forecast error falls by roughly a third. She then checks that the result is stable under reasonable changes to the hyperparameter priors before deploying the model.