0.5 — Joint, marginal, conditional, and Bayes' rule
Goal: State Bayes' rule, derive it from the joint, and read off the implicit generative story behind the binary classifier p(y=1|x) = σ(wᵀx).
1. Joints, marginals, and conditionals
Given a joint distribution on a pair :
-
The marginal of is obtained by summing/integrating out:
Marginalisation is the universal operation for getting rid of a variable you don't care about right now.
-
The conditional of given is the joint normalised by the marginal:
Conditioning is the universal operation for asking "what do I know about once I've observed ?".
These two are dual: marginalising forgets, conditioning updates.
2. The product rule (chain rule of probability)
Rearranging the definition of conditional probability gives the product rule:
The two factorisations exist because we can condition in either direction. The identity itself is trivial — but equating the two right-hand sides is exactly Bayes' rule.
3. Bayes' rule
Equate the two factorisations of the joint:
and solve for the conditional we typically want in inference:
The denominator is just normalisation; expanded via marginalisation,
it is the prior-weighted average likelihood of observing across all hypotheses. The four named pieces:
- — prior, what you believed about before seeing data.
- — likelihood, the model's probability of generating given hypothesis .
- — posterior, updated belief about after observing .
- — evidence / marginal likelihood, a normaliser.
In ML the model is usually parametrised by and we write for the likelihood; replaces in the formula and prior/posterior become priors/posteriors over parameters.
4. The binary classifier
This is the model behind logistic regression and behind the output layer of every binary deep classifier. The self-test in the roadmap asks: what is the implicit generative story?
The answer is not "we drew from some Gaussian and applied a deterministic rule". The model is more honest than that: it directly specifies the posterior and says nothing at all about . This is the discriminative stance: model directly; don't bother modelling how came to be.
Compare with the generative stance, which would model and , then derive the posterior by Bayes' rule:
For example, if we assumed (Gaussian class-conditionals with shared covariance) and a Bernoulli prior over , then a few lines of algebra (which we don't need today) give
for specific and derived from , and the prior. The logistic-regression functional form is consistent with a Gaussian generative story — but logistic regression itself doesn't commit to that story.
The point: is the same conditional as the one Bayes' rule would produce from a class-conditional Gaussian generative model, but logistic regression learns directly from the data without ever estimating the Gaussian parameters. Discriminative training is often more sample-efficient when all you need is the decision rule.
5. Independence and conditional independence
and are independent () iff
equivalently for all with . Observing tells you nothing new about .
and are conditionally independent given () iff
Conditional independence is the structural primitive behind graphical models, the naive-Bayes classifier (assumes features are independent given the label), and the layered structure of probabilistic deep models later on. Worth keeping in mind even when you don't draw a graph.
6. Where this is going
Bayes' rule is the lens through which we will read MLE, MAP, variational inference, and the discriminative-versus-generative distinction that runs all the way through the course. Cross-entropy as a loss (§0.7) is MLE on a discriminative model. The score function in policy gradient (Ch. 9) is the gradient of a log-likelihood. The "likelihood" of an LLM output token is the conditional next-token probability. Same machinery, used many times.
A test for a rare disease has 99% sensitivity () and 99% specificity (). The disease has prevalence in the screened population. A patient tests positive.
- Identify the prior, likelihood, and what you want (the posterior).
- Compute using Bayes' rule.
- The answer is surprisingly low. Why? Where does the false-positive rate enter?