Skip to content
mlmentorship

Bayes' rule and the posterior

How to update beliefs given evidence: posterior ∝ likelihood × prior. The foundation of Bayesian inference, naive Bayes, and probabilistic graphical models.

Published · 4 min read ·Core ·Foundation

Visual quick review

Visual first · depth when needed

Use natural-frequency branches to see why a rare prior can make false positives outnumber true positives even when sensitivity and specificity are both 99 percent.

Preparing the visual…

Summary

For random variables (parameters / hypothesis) and (data / evidence):

The posterior is proportional to the likelihood times the prior .

Bayes’ rule is the only mathematically consistent way to update probabilistic beliefs given new evidence. It underlies probabilistic ML (Gaussian processes, Bayesian deep learning), classification (naive Bayes), generative models (latent variable inference), and many engineering systems (Kalman filtering, sensor fusion).

The connection to MLE: the posterior peak (MAP estimate) collapses to MLE under a uniform prior. So MLE is a special case of Bayesian inference with no prior beliefs.

The four pieces

PieceNameWhat it is
PriorBeliefs about before seeing data
LikelihoodHow probable the data is under each hypothesis
PosteriorUpdated beliefs after seeing data
Evidence / marginal likelihoodNormalizing constant;

The evidence is often intractable (high-dimensional integral). For point estimates and many decisions you can ignore it.

The classic example

A medical test is 99% accurate: and . The disease has prevalence . A random person tests positive. What is ?

Learning objective

Why can a 99%-accurate test still make most positive results false?

Natural-frequency funnel for a rare disease test Start with 100,000 people. At 0.1 percent prevalence, 100 have the disease and 99,900 are healthy. With 99 percent sensitivity, the diseased branch contributes 99 true-positive results. With 99 percent specificity, one percent of the healthy branch contributes 999 false-positive results. The branches merge into 1,098 positive results, of which only 99, or about 9 percent, indicate disease. 100,000 people before testing 100 have disease prior: 0.1% 99,900 healthy prior: 99.9% 99% test positive 1% test positive 99 true positives 99% of 100 999 false positives 1% of 99,900 99 / (99 + 999) = 9% disease given a positive result
Read it this way: the rare prior creates only 100 opportunities for a true positive but 99,900 opportunities for a false positive. Both branches feed the positive-result denominator, so 999 false positives outnumber 99 true positives and only about 9% of positive results indicate disease.

Despite 99% test accuracy, about 91% of positive results are false. The prior strongly affects the posterior.

Conjugate priors

A prior is conjugate to a likelihood if the resulting posterior is in the same family (so updating stays in closed form).

LikelihoodConjugate priorPosterior family
Bernoulli/binomialBetaBeta
Categorical/multinomialDirichletDirichlet
Gaussian (mean, known )GaussianGaussian
Gaussian (precision)GammaGamma
PoissonGammaGamma

Used in: Thompson sampling for bandits (Beta-Bernoulli), online recsys updates, conjugate Gibbs samplers.

Approximate inference (when conjugacy fails)

Modern Bayesian deep learning rarely has closed-form posteriors. Standard approximations:

  • Laplace approximation: Gaussian centered at MAP with covariance from the Hessian.
  • Variational inference: optimize a parametric family to minimize .
  • MCMC (Metropolis-Hastings, HMC, NUTS): draw samples from the posterior asymptotically.
  • Stochastic-gradient Langevin / SGHMC: scale to large data via mini-batches.

Common pitfalls

  • Confusing likelihood with posterior. is not a probability distribution over ; it does not integrate to 1 over .
  • Ignoring the prior in low-data regimes. With small , the posterior is dominated by the prior.
  • Reporting MAP without uncertainty. A posterior contains more than its mode; the spread is often the more useful information.
  • Improper priors. Some “uniform” priors over unbounded parameter spaces don’t integrate; the posterior may still be proper (or may not be).