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):

[5 6 4 5 3 7 4 5 6 4]

 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

  1. Simulate 50 coin flips (n=1) 1000 times and plot histogram.

  2. Simulate quality check: 20 items, success probability 0.8, 1000 experiments.

  3. Compare p=0.2 vs p=0.8 for 10 trials.

You may also like...