ContentsChapter 2 · Probability1 of 6

2.1

Conditional probability and Bayes' rule

In this chapter
  1. 2.1Conditional probability and Bayes' rule
  2. 2.2Random variables
  3. 2.3Expectation, variance, covariance
  4. 2.4Bernoulli, binomial and Gaussian
  5. 2.5Change of variables
  6. 2.6Entropy and cross-entropy
Before you readA test catches 90% of people with a disease and wrongly flags 5% of healthy people. One person in a hundred has the disease. You test positive. How likely is it that you have it?
Watch: Bayes theorem, the geometry of changing beliefs · 3Blue1Brown

The conditional probability of A given B is the share of B in which A also happens:

P(A∣B)=P(A,B)P(B),P(B)>0.P(A \mid B) = \frac{P(A, B)}{P(B)}, \qquad P(B) > 0.

Rearranged, it is the product rule P(A,B)=P(A∣B) P(B)P(A, B) = P(A \mid B)\,P(B) Summing the joint probability over every case of A gives the sum rule, P(B)=∑aP(B∣A=a) P(A=a)P(B) = \sum_a P(B \mid A = a)\,P(A = a)

Write the product rule both ways round and divide to get Bayes’ rule, which turns a hypothesis H and evidence E around:

P(H∣E)=P(E∣H) P(H)P(E),P(E)=P(E∣H) P(H)+P(E∣¬H) P(¬H).P(H \mid E) = \frac{P(E \mid H)\,P(H)}{P(E)}, \qquad P(E) = P(E \mid H)\,P(H) + P(E \mid \neg H)\,P(\neg H).

P(H)P(H) is the prior, P(E∣H)P(E \mid H) the likelihood, P(E)P(E) the evidence and P(H∣E)P(H \mid E) the posterior. When the prior is small, most positives come from the large group without H, even if the test is good. That is the answer to the question above.

A and B are independent when P(A,B)=P(A) P(B)P(A, B) = P(A)\,P(B) which is the same as P(A∣B)=P(A)P(A \mid B) = P(A) knowing B tells you nothing about A.

In machine learning, H is a class label and E is the input. A classifier estimates P(class∣x)P(\text{class} \mid x) and generative models get it from Bayes’ rule.

Hnot H
P(H, E) = 0.090P(E) = 0.180P(H | E) = 0.500
The square is everyone. The left column is H, as wide as the prior. In each column the solid part is where the evidence E shows up. Seeing E throws away everything that isn't solid, so P(H | E) is the pink share of the solid area.
Recall
State Bayes' rule for a hypothesis HH and evidence EE
Recall
How do you compute the evidence P(E)P(E) in Bayes' rule?
Recall
What does it mean for AA and BB to be independent?
Exercise
Answer the question at the top: with P(D)=0.01P(D) = 0.01 P(+∣D)=0.9P(+ \mid D) = 0.9 and P(+∣¬D)=0.05P(+ \mid \neg D) = 0.05 find P(D∣+)P(D \mid +) to two decimal places.
Exercise
Machine A makes 70% of a factory's parts and 2% of them are faulty. Machine B makes the rest and 5% of them are faulty. Give P(faulty)P(\text{faulty}) and then P(B∣faulty)P(B \mid \text{faulty}) each to three decimal places.
Exercise
Roll a fair die. Let AA be 'even' and BB be 'at most 4'. Are AA and BB independent?