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 trials -
pβ probability of success in each trial -
sizeβ number of experiments / samples -
Values 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*p -
Histogram 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.
