Mathematics and Statistics for AI Intermediate 14 minutes

Probability Basics and Bayes’ Theorem

Conditional probability, independence and Bayes' theorem, and why intuition fails with rare medical tests.

Your progress in the track0%

Basic rules

  • \(0 \le P(A) \le 1\).
  • \(P(A \cup B) = P(A) + P(B) – P(A \cap B)\).
  • Conditional probability: \(P(A \mid B) = \dfrac{P(A \cap B)}{P(B)}\).

Bayes' theorem

$$P(H \mid D) = \frac{P(D \mid H)\, P(H)}{P(D)}$$

SymbolNameMeaning
P(H)Prior probabilityOur belief before the data
P(D | H)LikelihoodHow well the data fits the hypothesis
P(H | D)Posterior probabilityOur belief after the data

The medical test example

A disease with 1% prevalence, and a test with 90% sensitivity and 90% specificity. Out of 1,000 people:

  • 10 are sick, and the test detects 9 of them.
  • 990 are healthy, and the test gives 99 of them a false positive result.
  • Of 108 positive results, only 9 are real: about 8%.

The link to machine learning

  • The classifier Naive Bayes applies the theorem with the assumption that the features are conditionally independent.
  • When a model is moved to a population with a different prevalence, the positive predictive value changes even if sensitivity and specificity stay the same.
  • The metrics Precision and Recall correspond to positive predictive value and sensitivity.
prev, sens, spec = 0.01, 0.90, 0.90
ppv = sens * prev / (sens * prev + (1 - spec) * (1 - prev))
print(round(ppv, 3))   # 0.083

Lesson terms

Conditional probability
The probability of an event given that another event occurred, equal to the probability of both occurring divided by the probability of the condition.
Independence
Two events are independent if knowing one does not change the probability of the other.
Bayes' theorem
A relationship linking the posterior probability to the prior probability and the likelihood: P(y|x) = P(x|y)P(y)/P(x).

Abstract

Probability measures uncertainty. The conditional probability P(A|B) is the probability of A given that B occurred. Bayes' theorem reverses the condition, linking the posterior probability to the prior probability and the likelihood. Ignoring the prior probability (the prevalence) leads to a common fallacy: an accurate test for a rare disease may have mostly false positive results.

Review questions

  1. Why does a test with 99% sensitivity have a low positive predictive value for a rare disease?

    Because the number of healthy people is very large, so even a small proportion of false positives among them exceeds the number of truly sick people.

  2. What is the difference between P(A|B) and P(B|A)?

    The first is the probability of A given B, and the second is the reverse, and they are generally not equal.

Sources and references

  1. Deisenroth, Faisal & Ong — Mathematics for Machine Learning (Ch. 6)
  2. Goodfellow, Bengio & Courville — Deep Learning (Ch. 3)

Complete the lesson