Bayes' Theorem
Apply Bayes' Theorem with P(A|B) = P(B|A) × P(A) / P(B).
Update probabilities based on new evidence and conditional information.
The Formula
Bayes' Theorem calculates the probability of an event based on prior knowledge of conditions related to that event. It lets you update your beliefs when you receive new evidence.
Variables
| Symbol | Meaning |
|---|---|
| P(A|B) | Probability of A given that B has occurred (posterior probability) |
| P(B|A) | Probability of B given that A has occurred (likelihood) |
| P(A) | Probability of A on its own (prior probability) |
| P(B) | Probability of B on its own (marginal probability) |
Example 1
A medical test is 99% accurate. The disease affects 1 in 1,000 people. If you test positive, what is the probability you actually have the disease?
P(Disease) = 0.001, P(No Disease) = 0.999
P(Positive | Disease) = 0.99
P(Positive | No Disease) = 0.01 (false positive rate)
P(Positive) = (0.99 × 0.001) + (0.01 × 0.999) = 0.00099 + 0.00999 = 0.01098
P(Disease | Positive) = (0.99 × 0.001) / 0.01098
P(Disease | Positive) = 0.0902 or about 9% — Even with a positive test, there is only a 9% chance of having the disease.
Example 2
60% of emails are spam. A filter catches 95% of spam and incorrectly flags 3% of legitimate emails. If an email is flagged, what is the probability it is actually spam?
P(Spam) = 0.60, P(Not Spam) = 0.40
P(Flagged | Spam) = 0.95
P(Flagged | Not Spam) = 0.03
P(Flagged) = (0.95 × 0.60) + (0.03 × 0.40) = 0.57 + 0.012 = 0.582
P(Spam | Flagged) = (0.95 × 0.60) / 0.582
P(Spam | Flagged) = 0.979 or about 97.9% — A flagged email is almost certainly spam.
When to Use It
Use Bayes' Theorem when:
- You have a test result and want to know the true probability
- Updating predictions based on new evidence
- Building spam filters, recommendation systems, or diagnostic tools
- Evaluating the reliability of screening tests in medicine