Skip to content
AI-grafen
DAI developerStatistics and probability· about 45 min· fundamentals that rarely change· verified 2026-09-20· EN

Conditional probability

Be able to calculate P(A|B), decide independence and avoid the common fallacies.

Prerequisites

Intuition

Conditional probability P(A|B) = the probability of A given that B has already happened.

The formula: P(A|B) = P(A and B) / P(B).

An example: in a class of 30 pupils, 12 play football, 8 play floorball and 5 play both.

P(floorball | football) = 5/12 ≈ 0.42 — among the footballers, 42 % also play floorball, against 8/30 ≈ 27 % in the whole class. Knowing that somebody plays football changes the probability. The events are then dependent.

Independence means that P(A|B) = P(A) — the information changes nothing.

Formal

Bayes' theorem: P(A∣B)=P(B∣A) P(A)P(B)P(A\mid B) = \dfrac{P(B\mid A)\,P(A)}{P(B)}.

The classic test example. A disease has a prevalence of 1 %. A test finds 99 % of the ill (the sensitivity) and gives a false positive in 5 % of the healthy cases. You test positive. How likely is it that you are ill?

Out of 10 000 people:

  • 100 ill → 99 positives.
  • 9 900 healthy → 495 false positives.
  • Total positives: 594. The share genuinely ill: 99/594≈99/594 \approx 17 %.

Despite a «99 per cent» test you are probably healthy. The fallacy of answering «99 %» is called the base rate fallacy: you forget how uncommon the disease is.

The same arithmetic holds for every rare-event detector: fraud, security alarms, AI-cheating detectors. At a low prevalence the false positives dominate — however good the test sounds.

Code

prevalence, sensitivity, false_pos = 0.01, 0.99, 0.05

p_pos = prevalence * sensitivity + (1 - prevalence) * false_pos
p_ill_given_pos = prevalence * sensitivity / p_pos
print(round(p_ill_given_pos, 3))         # 0.167

for prev in (0.001, 0.01, 0.1, 0.5):
    p = prev * 0.99 / (prev * 0.99 + (1 - prev) * 0.05)
    print(prev, round(p, 3))
# 0.001 0.019   ← almost every positive is false
# 0.01  0.167
# 0.1   0.688
# 0.5   0.952

Mastery means

  • Calculates P(A|B) from a two-way table
  • Decides independence and avoids the base rate fallacy

Sign in to do the exercises and build your mastery up.

Sources

All the sources and licences