Statistics Binomial Distribution
The binomial distribution models the number of successes across a fixed number of independent yes/no trials, each with the same success probability.
What Is a Binomial Distribution?
The binomial distribution describes situations with a fixed number of independent trials, where each trial ends in one of exactly two outcomes — success or failure — and the probability of success stays the same every time. Flipping a coin 10 times and counting heads, or testing 20 manufactured parts and counting defects, are both binomial scenarios.
The Binomial Formula
The probability of getting exactly k successes in n trials is P(X = k) = C(n, k) × p^k × (1 − p)^(n − k), where n is the number of trials, p is the probability of success on a single trial, and k is the specific number of successes we're asking about. The C(n, k) term counts how many different orderings of successes and failures produce exactly k successes.
Example: Exactly 3 Heads in 5 Coin Flips
import math
n = 5 # number of trials (flips)
p = 0.5 # probability of heads on each flip
k = 3 # exactly 3 heads
probability = math.comb(n, k) * (p ** k) * ((1 - p) ** (n - k))
print(f"P(X = {k}) = {probability:.4f}") # 0.3125- A fixed number of trials, n.
- Each trial has exactly two possible outcomes: success or failure.
- The probability of success, p, is the same on every trial.
- The trials are independent — one outcome doesn't affect another.
Mean and Variance
For a binomial distribution, the mean (expected number of successes) is simply n × p, and the variance is n × p × (1 − p). These formulas let you summarize an entire distribution with just two numbers, without listing every possible outcome.
Example: Defective Items in a Batch
import math
n = 10 # items inspected
p = 0.2 # defect rate
k = 2 # exactly 2 defective items
p_exactly_2 = math.comb(n, k) * (p ** k) * ((1 - p) ** (n - k))
mean = n * p
variance = n * p * (1 - p)
print(f"P(X = 2 defective) = {p_exactly_2:.4f}") # 0.3020
print(f"Mean = {mean}, Variance = {variance}") # Mean = 2.0, Variance = 1.6Binomial reasoning underlies quality control (counting defective units), A/B testing (counting conversions among visitors), and any repeated-trial process where you only care whether each trial succeeded or failed.