beginnerstatistics

Conditional Probability

How does knowing one thing change the probability of another?

Key Points

What it is

Conditional probability is the probability of an event occurring given that another event has already occurred. Written as P(A|B), it is read as 'the probability of A given B.' It answers the question: now that I know B happened, how likely is A? Conditional probability is not a special type of probability — it is just probability calculated on a restricted subset of possibilities.

Why it exists

Most real-world probability questions involve context. Not 'what is the probability this patient has cancer' but 'what is the probability this patient has cancer given they tested positive.' The test result is new information — it should change the probability. Conditional probability is the formal tool for updating probabilities when you learn something new. Without it, you cannot build classifiers, medical diagnostic systems, spam filters, or recommendation engines.

What it measures

Conditional probability measures how much one event narrows down the likelihood of another. If P(rain) = 0.3 but P(rain | dark clouds) = 0.8, then dark clouds are a strong signal. The difference between the unconditional and conditional probability tells you how informative the condition is — which is exactly the concept behind information gain in decision trees.

Intuition

Imagine a standard deck of 52 cards. P(King) = 4/52 ≈ 0.077. Now someone tells you the card is a face card (Jack, Queen, or King). There are 12 face cards, 4 of which are Kings. So P(King | face card) = 4/12 ≈ 0.333. The sample space shrank from 52 to 12, and the probability jumped from 7.7% to 33.3%. The condition did not change the card — it changed what you know, and that changed the probability.

Example

In a dataset of 1000 emails: 200 are spam. Of the 200 spam emails, 180 contain the word 'free'. Of the 800 legitimate emails, 40 contain 'free'.

P(spam) = 200/1000 = 0.2. P(spam | contains 'free') = 180/(180+40) = 180/220 ≈ 0.818. Knowing the email contains 'free' raises the probability of spam from 20% to 82%. This is exactly how a Naive Bayes spam filter works.

Formulas

Conditional Probability

P(A∣B)=P(A∩B)P(B)P(A \mid B) = \frac{P(A \cap B)}{P(B)}
  • P(A|B) — probability of A given that B occurred
  • P(A ∩ B) — probability that both A and B occur together
  • P(B) — probability of B — the condition. Must be > 0.

Bayes' Theorem

P(A∣B)=P(B∣A)⋅P(A)P(B)P(A \mid B) = \frac{P(B \mid A) \cdot P(A)}{P(B)}
  • P(A|B) — posterior — updated probability of A after observing B
  • P(B|A) — likelihood — how probable is B if A is true
  • P(A) — prior — initial probability of A before seeing B
  • P(B) — marginal probability of B — acts as a normalizing constant

When to use

When not to use

Common mistakes

In practice

Conditional probability is the mathematical core of Naive Bayes classifiers, logistic regression, and all probabilistic models. In Bayesian statistics, updating a prior with observed data to get a posterior is a direct application of Bayes' theorem. In NLP, language models estimate P(next word | previous words). In recommendation systems, P(user clicks | user profile, item features) is the quantity being predicted. Every use of model.predict_proba() in scikit-learn is computing a conditional probability.

Was this concept helpful?

Spot an error or gap? Suggest an edit →

Related concepts

probability-basicshypothesis-testingnormal-distributioncorrelation-vs-causation
Chirp at me!