Home / Maths for AI / Symbols / Probability and statistics

Conditional probability

Say it: "the probability of A given B"

What it means

The probability of AA when we already know BB happened: P(A∣B)=P(A∩B)P(B)P(A \mid B) = \frac{P(A \cap B)}{P(B)}. Bayes' theorem turns it around: P(A∣B)=P(B∣A)P(A)P(B)P(A \mid B) = \frac{P(B \mid A)P(A)}{P(B)}.

Example

P(sick∣positive test)≠P(positive test∣sick)P(\text{sick} \mid \text{positive test}) \ne P(\text{positive test} \mid \text{sick})

Mixing these two up is a classic mistake.

In code

p_pos_sick, p_sick, p_pos_healthy = 0.9, 0.02, 0.05
p_pos = p_pos_sick * p_sick + p_pos_healthy * (1 - p_sick)
print(round(p_pos_sick * p_sick / p_pos, 3))

Output

0.269

Where it appears in machine learning

Every classifier estimates P(y∣x)P(y \mid \mathbf{x}): the probability of a label given the features.

Related symbols

Learn it properly in the free lesson Probability & Distributions, with practice questions that check your answers.