Probability Basics › Independence and Conditional Probability
Machine Learning from ScratchAll chapters Probability Basics › Independence and Conditional ProbabilityOne section · Sections in this chapter6 / 12 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Real-world phenomena rarely occur in isolation. Events influence each other in complex ways. Probability theory provides tools to reason about relationships between events, distinguishing between cases where events are unrelated (independent) and cases where knowledge of one event changes our beliefs about another (dependent).
Two events and are independent if knowing whether one occurred provides no information about whether the other occurred. Mathematically, independence means that the probability of both events occurring equals the product of their individual probabilities:
This reads as: "the probability that both and occur equals the probability of multiplied by the probability of ."
Independence is a simplifying assumption that appears throughout statistical modeling. When we assume observations are independent, we can multiply their probabilities to compute joint likelihoods, enabling tractable inference in complex models. However, incorrectly assuming independence when dependence exists can lead to underestimating uncertainty and making overconfident predictions.
When events are dependent, we use conditional probability to express how the probability of one event changes given knowledge about another. The conditional probability of event given that event has occurred is written and defined as:
This formula says that the conditional probability equals the probability of both events occurring divided by the probability of the conditioning event. Rearranging this definition gives us the multiplication rule:
Conditional probability forms the basis for Bayes' theorem, one of the most important results in probability theory and the foundation of Bayesian statistical inference:
Bayes' theorem allows us to "invert" conditional probabilities, computing from . This inversion has many applications: in medical diagnosis, we might know the probability of a positive test given a disease, but we really want the probability of the disease given a positive test. In spam filtering, we observe words in an email and want to compute the probability the email is spam. In machine learning, we observe data and want to infer the probability of different model parameters.
Example: Conditional Probability and Bayes' Theorem
This example demonstrates how conditional probability updates our beliefs based on new information. We simulate a medical testing scenario where Bayes' theorem helps us understand the difference between the probability of a positive test given disease presence and the probability of disease given a positive test.
Let's work through a concrete example step by step. Suppose we have:
- Prior probability of disease: (1% of the population has the disease)
- Test sensitivity (true positive rate): (95% of sick people test positive)
- Test specificity (true negative rate): (90% of healthy people test negative)
From specificity, we can derive the false positive rate:
Question: If someone tests positive, what is the probability they have the disease?
We want to find using Bayes' theorem:
Step 1: Calculate using the law of total probability
The total probability of testing positive considers both paths: having the disease and testing positive, or not having the disease and testing positive (false positive).
Step 2: Apply Bayes' theorem
In probability and logic, (called "negation" or "not") denotes the complement of an event. So means "not D" or "the event D does not occur." In our medical example, represents a person who does not have the disease. You may also see this written as , , or in different textbooks. They all mean the same thing: the complement of event .
Interpretation: Even with a positive test result, the probability of having the disease is only about 8.8%! This counterintuitive result occurs because:
- The disease is rare (low prior probability)
- The false positive rate (10%) applied to the large healthy population generates many false positives
- These false positives "dilute" the true positives
This phenomenon is called the base rate fallacy and highlights why understanding conditional probability is essential for interpreting medical tests, machine learning classifiers, and any diagnostic system.

Sensitivity (also called the true positive rate) measures how well a test detects the condition when it is present. A sensitivity of 95% means that if 100 people with the disease are tested, 95 will correctly receive a positive result.
Specificity (also called the true negative rate) measures how well a test correctly identifies people without the condition. A specificity of 90% means that if 100 healthy people are tested, 90 will correctly receive a negative result, but 10 will receive a false positive.
Despite the test appearing highly accurate (95% sensitivity, 90% specificity), the posterior probability of having the disease given a positive test is only about 8.8%. This counterintuitive result occurs because the disease is rare (1% prevalence). With 99 healthy people for every 1 sick person, even a 10% false positive rate generates many more false positives than true positives. This example illustrates why screening tests for rare conditions often require confirmation with follow-up testing.