CV Courseversity

Bayesian Methods

Develops Bayes' theorem, priors, likelihoods, posterior updating, and Bayesian decision theory as the framework AI systems use to revise beliefs rationally as new evidence arrives.

“A rare disease affects 1% of a population, and a diagnostic test correctly flags 90% of true cases but also produces false positives 5% of the time on healthy patients. If a patient tests positive, is it really likely they have the disease? Most people's intuition badly overestimates the answer — and getting it right requires exactly the machinery this module builds: priors, likelihoods, posterior inference, and Bayesian decision theory, the framework behind AI systems from naive Bayes spam filters to uncertainty-aware neural networks.”

Priors, Likelihoods, and Posterior Updating · 15 min

Bayes' theorem is a single formula that tells us precisely how to update a belief in light of new evidence: P(H | E) = P(E | H) · P(H) / P(E), where H is a hypothesis and E is observed evidence (Bishop's Pattern Recognition and Machine Learning develops this as the foundation of the book's Bayesian viewpoint). Three named quantities appear in this formula: the prior, P(H), which is the probability assigned to the hypothesis before seeing any evidence; the likelihood, P(E | H), which is the probability of observing the evidence if the hypothesis were true; and the posterior, P(H | E), the updated probability of the hypothesis after the evidence has been taken into account. Bayesian inference is, in essence, the disciplined process of turning a prior belief plus new data into a posterior belief, replacing gut-feeling updates with an exact, repeatable calculation.

The disease-testing scenario in this module's essential question is a classic worked illustration of exactly why intuition often fails here. Let the prior probability of disease be P(D) = 0.01, the test's sensitivity (true positive rate) be P(+ | D) = 0.9, and its false positive rate be P(+ | not D) = 0.05. Bayes' theorem gives P(D | +) = [P(+ | D) × P(D)] / [P(+ | D) × P(D) + P(+ | not D) × P(not D)] = (0.9 × 0.01) / (0.9 × 0.01 + 0.05 × 0.99) = 0.009 / 0.0585 ≈ 0.154 — meaning a positive test result raises the probability of disease only to about 15.4%, not 90%, because the disease is rare enough that false positives among the large healthy population outnumber true positives (MIT 18.05's coverage of Bayesian updating develops this same base-rate reasoning, and it is one of the most consistently miscalculated problems in introductory statistics).

This same mechanism drives real AI systems. A naive Bayes spam classifier treats 'is this email spam' as the hypothesis and the words in the email as evidence, multiplying a prior probability of spam by the likelihood of observing each word under the spam and non-spam hypotheses to arrive at a posterior probability of spam given the full message (Russell & Norvig's AIMA presents naive Bayes as a canonical probabilistic classifier). More broadly, any AI system that must revise its beliefs as new data streams in — from a robot updating its estimate of an obstacle's position after each sensor reading to a recommender system updating a user's inferred preferences after each click — is running the same prior-times-likelihood-equals-posterior computation introduced here, over and over, at every new piece of evidence it observes, with yesterday's posterior serving as tomorrow's prior.

Bayesian Decision Theory and Predictive Modelling · 15 min

Once a posterior distribution over a hypothesis or parameter has been computed, an AI system still has to act — and Bayesian decision theory provides the rule for doing so rationally: choose the action that minimizes expected loss under the posterior (Bishop's PRML develops this formally, connecting probability theory directly to decision-making). A common simplification is the maximum a posteriori (MAP) estimate, which simply picks the single hypothesis or parameter value with the highest posterior probability, ignoring the rest of the distribution's shape; in the disease-testing example, if 15.4% posterior probability of disease was still the most likely single diagnosis among the options considered, MAP would select it, even though the full posterior — carrying the actual 15.4% figure — contains far more usable information than that single point estimate does on its own, since a downstream decision-maker may need the exact probability, not just the most likely label, to weigh the cost of a missed diagnosis.

Working with the full posterior rather than collapsing it to a single point matters most when predicting new, unseen data. The posterior predictive distribution combines uncertainty about model parameters (captured in the posterior) with the model's own randomness to produce a prediction that honestly reflects both sources of uncertainty, rather than pretending the parameters are known exactly (Bishop's PRML; CS229's notes similarly motivate why point estimates like maximum likelihood can understate true predictive uncertainty). This is precisely the idea behind Bayesian neural networks and other uncertainty-aware AI models: instead of learning one fixed set of weights, they maintain a posterior distribution over plausible weight settings, and their predictions are computed by averaging over that whole distribution, which is why they can report not just a prediction but a calibrated measure of how confident they genuinely are in it, a property that matters enormously whenever an AI system's mistakes carry real-world consequences.

The contrast with purely frequentist statistical methods, covered in the previous module, is instructive rather than adversarial: frequentist inference treats a parameter as fixed but unknown and asks how an estimator behaves across repeated sampling, while the Bayesian approach treats the parameter itself as a random variable and directly computes a probability distribution over it given the data actually observed (AIMA discusses this as one dimension along which probabilistic AI approaches differ). In practice, AI systems often blend both traditions freely — a naive Bayes classifier's word-probability parameters might be estimated by maximum likelihood, a frequentist technique, and then combined via Bayes' theorem to produce Bayesian posterior predictions, illustrating that the two frameworks introduced across these two modules are complementary tools in the same statistical toolbox, not mutually exclusive philosophies to choose between once and for all, and that a working AI practitioner benefits from being fluent in both.

Practice

Updating Beliefs with Bayes' Theorem

Prior × Likelihood Posterior belief before data belief after data

A prior belief is combined with the likelihood of observed evidence to produce an updated, posterior belief.

  • Bayes' theorem multiplies a prior by a likelihood to produce a posterior — the mathematical core of updating beliefs from evidence.
  • When an event is rare, even an accurate test can leave the posterior probability far below the test's own accuracy rate, due to the base-rate effect.
  • Bayesian decision theory chooses actions to minimize expected loss under the posterior, rather than relying on a single point estimate.

Recall Practice

Bayes' theorem componentsClick to reveal
A spam filter estimates P(spam | 'free'). Which quantity in Bayes' theorem represents the probability of the word 'free' appearing, given that a message is spam?
That is the likelihood, P('free' | spam), one of the three components — prior, likelihood, posterior — combined by Bayes' theorem.
Base-rate reasoningClick to reveal
A rare medical condition has a 1% prevalence, and a positive test result only raises the probability of the condition to about 15%, despite the test being 90% accurate on true cases. Why doesn't the posterior match the test's accuracy?
Because the condition is rare, false positives among the large healthy population outnumber true positives, so Bayes' theorem yields a posterior far below the test's raw accuracy rate.
MAP vs. full posteriorClick to reveal
A model reports one 'best' diagnosis using MAP estimation instead of the full posterior distribution. What information does this discard?
It discards the relative probabilities of the other plausible hypotheses and any measure of how confident the model actually is, keeping only the single most probable value.
Predictive uncertaintyClick to reveal
Why might a Bayesian neural network's prediction come with a wider uncertainty range than a standard neural network's prediction on the same input?
Because it averages predictions over a full posterior distribution of plausible weight values rather than using one fixed set of weights, so it can honestly reflect uncertainty about which weights are correct.

Glossary

Prior
The probability assigned to a hypothesis before observing new evidence.
Likelihood
The probability of observing the evidence if a given hypothesis were true.
Posterior
The updated probability of a hypothesis after evidence has been incorporated via Bayes' theorem.
Bayes' theorem
The formula P(H|E) = P(E|H)·P(H) / P(E) that converts a prior and a likelihood into a posterior.
MAP estimate
The single hypothesis or parameter value with the highest posterior probability.
Posterior predictive distribution
A prediction for new data that accounts for both the model's randomness and uncertainty in its parameters.
Practical Activity

Computing a Bayesian Posterior by Hand

This is a virtual, hand-computed exercise using only the numbers supplied — no live classifier or real email dataset is used. A naive Bayes spam filter has a prior P(spam) = 0.2. The word 'free' appears with likelihood P('free' | spam) = 0.6 and P('free' | not spam) = 0.05. Using Bayes' theorem, compute the posterior P(spam | 'free') by hand and verify it comes out to 0.75.

Ready to test yourself?

5 questions on this module.

Start Quiz