Home / Probability

Conditional Probability

Learning that B happened does not change the world — it shrinks it. Drag the two events and watch the universe you are allowed to count in get smaller.

Events

4.0
5.0
5.0

throw away every outcome outside B

The Sample Space

400 outcomes

Every dot is one equally likely outcome. Probabilities here are exact counts, not areas.

Counts

P(A) 0.00
P(B) 0.00
P(A and B) 0.00

Conditionals

P(A given B)
0.00
0 / 0
P(B given A) 0.00
Independent? no

Conditional Probability: A Practical Guide

What "given" actually does, and why swapping the two sides is the most expensive mistake in statistics.

Quick Context

Probability counts favourable outcomes against all possible outcomes. Conditional probability changes one thing: it shrinks what counts as possible.

P(A | B) is read "the probability of A given B". The bar does not mean division and it does not mean "and". It means: assume B happened, throw away every outcome where it did not, and ask about A within what remains.

The formula is just a recount

P(A | B) = P(A and B) / P(B)

Look at what this does with the grid above. The denominator was 400 — the whole sample space. Conditioning on B replaces it with however many outcomes are in B. The numerator counts the outcomes that are in both, because those are the only ones in the shrunken world where A is also true.

Tick Condition on B and the picture does exactly this: everything outside B is discarded, and the readout underneath shows the fraction as a plain count of dots. The formula is bookkeeping for that operation, not a separate idea.

Independence, defined properly

A and B are independent when knowing B tells you nothing about A:

P(A | B) = P(A)

Shrinking the world to B leaves A's share of it unchanged. Equivalently, and more symmetrically, P(A and B) = P(A) × P(B) — which is the multiplication rule everyone learns, now with the condition attached that makes it valid.

Multiplying probabilities when the events are not independent is one of the most common errors in applied statistics, and it always understates joint risk when the events tend to occur together.

Interactive Exploration Guide

  1. Watch the world shrink. Tick Condition on B. The dots outside B fade out and P(A given B) is the fraction of the survivors that are blue. Untick it and the denominator goes back to all 400.
  2. Find independence. Set the Preset to Independent. P(A given B) and P(A) now read the same number — knowing B happened has told you nothing at all about A.
  3. Break it deliberately. Drag the Separation slider away from that setting. The two numbers come apart immediately, and Independent flips to no. Independence is a knife-edge condition, not a typical one.
  4. Make them incompatible. Set the Preset to Mutually exclusive. P(A and B) is zero, so P(A given B) is zero: if B happened, A certainly did not. Note that this is the opposite of independent — B is now maximally informative.
  5. See a certainty. Set the Preset to A inside B. Every outcome in A is also in B, so P(B given A) is exactly 1 while P(A given B) is much smaller. The two conditionals are nothing like each other.
  6. Meet the base-rate trap. Set the Preset to Rare A, common B and compare P(A given B) with P(B given A). One is small, the other is large, from the same two events. Reversing them is the error behind almost every misread medical test.

P(A|B) is not P(B|A)

This is worth stating in its own section because it causes more real-world damage than any other confusion in probability.

"Given the patient has the disease, the test is positive 99% of the time" is a statement about P(positive | disease). What a patient wants to know is P(disease | positive). Those are different numbers, and when the disease is rare they are wildly different — the second can be under 10% while the first is 99%.

The Rare A preset above shows the same asymmetry with nothing but dots. Converting between the two directions requires knowing how common the disease is to begin with, and the machinery for doing it is Bayes' theorem, which is the next module and is built directly on this one.

Where it shows up in machine learning

  • Every classifier is estimating P(class | features). That is a conditional probability and nothing else.
  • Naive Bayes is named for the assumption that features are conditionally independent given the class — which is usually false, and works anyway.
  • Precision and recall are the two directions of the same pair. Precision is P(actually positive | predicted positive); recall is P(predicted positive | actually positive). Reporting one when you meant the other is exactly this mistake.
  • Language models predict P(next token | everything so far) — a conditional probability with a very large condition.

What usually goes wrong

  • Swapping the two sides. Covered above, and worth checking every single time you read a conditional claim in the wild.
  • Multiplying without independence. P(A and B) = P(A)P(B) only holds when the events are independent. Applied to correlated failures it dramatically understates the chance of both happening.
  • Confusing exclusive with independent. They are close to opposites. Mutually exclusive events are maximally dependent: one occurring guarantees the other did not.
  • Conditioning on something with probability zero. The formula divides by P(B), so it is undefined when B cannot happen. Shrink the world to nothing and there is nothing left to count.

Key Takeaway

Conditioning on B does not change the outcomes, it discards the ones where B did not happen, so P(A | B) is simply the count of outcomes in both events divided by the count in B. Independence is the special case where that shrinking leaves A's share unchanged, which is exactly when P(A and B) = P(A)P(B) is valid and not before. The two conditionals P(A|B) and P(B|A) are different numbers and can differ enormously when one event is rare — converting between them is what Bayes' theorem is for.

Predict, then reveal

About to run: Find independence. Before it does — what happens to the readout?

Committing to an answer first is the point — the reveal runs the experiment on the visualisation above and reads the real value back, so nothing here is scripted.

Recall check

0 of 3

Say the answer out loud before you reveal it — recalling it is what makes it stick, and rereading it is not.

  1. Without scrolling back — what is the one-line takeaway from this module?

  2. What does this module say about “Quick Context”?

  3. What does this module say about “P(A|B) is not P(B|A)”?

Cheat sheet

Conditional Probability

Learning that B happened does not change the world — it shrinks it. Drag the two events and watch the universe you are allowed to count in get smaller.

MATHS · vizlearn.in/maths/conditional_probability.html