Binomial Distribution
🎲 Binomial Distribution in Python
The Binomial Distribution models the number of successes in a fixed number of independent trials, each with the same probability of success.
It’s widely used in coin tosses, quality control, and yes/no experiments.
1. Characteristics of Binomial Distribution
n→ number of trialsp→ probability of success in each trialsize→ number of experiments / samplesValues range from 0 to
n
Probability Mass Function (PMF):
P(X=k)=(nk)pk(1−p)n−kP(X = k) = \binom{n}{k} p^k (1-p)^{n-k}
Where:
kk = number of successes
(nk)\binom{n}{k} = combinations of n choose k
2. Generate Binomial Data Using NumPy
Output (example):
3. Visualize Binomial Distribution
Peaks around expected value:
E[X] = n*pHistogram shows discrete outcomes
4. Change Probability or Number of Trials
5. Compare Two Probabilities
Lower probability → peak closer to 0
Higher probability → peak closer to
n
6. Compute Mean and Variance
Theoretical values:
Mean = n∗pn * p
Variance = n∗p∗(1−p)n * p * (1-p)
🎯 Practice Exercise
Simulate 50 coin flips (n=1) 1000 times and plot histogram.
Simulate quality check: 20 items, success probability 0.8, 1000 experiments.
Compare p=0.2 vs p=0.8 for 10 trials.
