Marginal likelihood

Also known as: model evidence · Bayesian evidence

On this page 8

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.

QuantityNotationRole
Priorp(θ | M)Beliefs about parameters before the data
Likelihoodp(D | θ, M)Fit of specific parameter values to the data
Posteriorp(θ | D, M)Updated beliefs about parameters
Marginal likelihoodp(D | M)Support for the whole model, normalizing constant
Quantities in Bayes’ theorem and their roles

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.

MethodPrincipleTypical accuracyMain limitation
Analytic solutionClosed-form integralExactOnly conjugate or Gaussian models
Laplace approximationGaussian fit around the posterior modeGood for unimodal posteriorsPoor for skewed or multimodal shapes
BICLarge-sample asymptotic of LaplaceRoughIgnores the prior, needs many data points
Evidence lower boundVariational bound on log evidenceLower bound onlyGap depends on the variational family
Importance samplingWeighted samples from a proposalGood with a good proposalHigh variance in high dimensions
Nested samplingIntegration over likelihood contoursGood for moderate dimensionsComputationally expensive
Thermodynamic integrationPath between prior and posteriorHighRequires many MCMC runs
Common estimation methods

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 modelNatural logStrength of evidence
1 to 30 to 1.1Barely worth mentioning
3 to 201.1 to 3Positive
20 to 1503 to 5Strong
Above 150Above 5Very strong
Interpreting Bayes factors

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.

MistakeConsequenceRemedy
Vague or improper priorsEvidence undefined or arbitrarily lowUse proper, justified priors
Harmonic mean estimatesUnstable, misleading valuesUse nested or bridge sampling
Treating ELBO as evidenceBiased model rankingCompare bounds with caution
Overfitting hyperparametersOverconfident predictionsCheck with held-out predictive performance
Pitfalls and remedies

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.