Free tutorials & notes in Hindi & English · Clean code examples 🧰 Free PDF & Image Tools →
📐 Week 5 – Statistics & Probability  ·  Day 28

Day 28: Normal, Binomial & Poisson Distributions

⏱ 2 hours📶 Intermediate🎯 100% self-study
Day 28 / 60

✅ Today you will learn

  • Discrete vs continuous distributions
  • Binomial: “k successes in n tries”
  • Poisson: “events per hour/day”
  • Normal: the bell curve and 68-95-99.7
  • pmf, pdf, cdf and ppf with scipy.stats

🏢 In the real world

A call centre receives on average 12 calls an hour. How many agents do they need so that callers almost never wait? An online store converts 3% of visitors – what is the chance a 200-visitor ad campaign gets zero sales? Distributions answer these planning questions before anything happens.

Discrete vs continuous

Discrete (counts)

  • Values: 0, 1, 2, 3 …
  • Binomial, Poisson
  • pmf = P(X = k)
  • Orders today, calls per hour

Continuous (measurements)

  • Any value in a range
  • Normal, uniform, exponential
  • pdf = density; P(X = exact) = 0
  • Height, delivery time, temperature

Binomial distribution

n independent tries, each with success probability p. X = number of successes. Mean = n·p, SD = √(n·p·(1−p)).

Python
from scipy import stats
n, p = 200, 0.03                       # 200 visitors, 3% conversion
X = stats.binom(n, p)
print("Expected sales:", X.mean(), "| SD:", round(X.std(), 2))
print("P(0 sales)   =", round(X.pmf(0), 4))
print("P(≤ 3 sales) =", round(X.cdf(3), 3))
print("P(≥ 10 sales)=", round(1 - X.cdf(9), 4))
Expected sales: 6.0 | SD: 2.41 P(0 sales) = 0.0023 P(≤ 3 sales) = 0.147 P(≥ 10 sales)= 0.0808
Python
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
k = np.arange(0, 16)
fig, ax = plt.subplots(figsize=(9, 3.6))
for p, c in [(0.03, "#4f46e5"), (0.05, "#f59e0b")]:
    ax.bar(k + (0.2 if p == 0.05 else -0.2), stats.binom.pmf(k, 200, p), width=0.4, color=c, label=f"conversion {p:.0%}")
ax.set_title("Sales from 200 visitors – binomial pmf"); ax.set_xlabel("number of sales"); ax.set_ylabel("probability"); ax.legend()
plt.show()
Binomial pmf bars for 3% and 5% conversion
Raising conversion from 3% to 5% shifts the whole distribution right.

Poisson distribution

Counts of events in a fixed time or space when events happen independently at an average rate λ. Mean = variance = λ.

Python
from scipy import stats
lam = 12                                   # calls per hour
X = stats.poisson(lam)
print("P(exactly 12 calls) =", round(X.pmf(12), 3))
print("P(more than 18)     =", round(1 - X.cdf(18), 3))
for agents_capacity in [14, 16, 18, 20]:
    print(f"capacity {agents_capacity} calls/h → handles all calls {X.cdf(agents_capacity) * 100:.1f}% of hours")
P(exactly 12 calls) = 0.114 P(more than 18) = 0.037 capacity 14 calls/h → handles all calls 77.2% of hours capacity 16 calls/h → handles all calls 89.9% of hours capacity 18 calls/h → handles all calls 96.3% of hours capacity 20 calls/h → handles all calls 98.8% of hours
💼 Staffing decision

If each agent handles 4 calls an hour, capacity 20 needs 5 agents and covers almost every hour. Capacity 16 (4 agents) fails in roughly 1 hour out of 10. Poisson turns a guess into a service level.

Normal distribution

Python
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
mu, sd = 30, 5                            # delivery time in minutes
x = np.linspace(10, 50, 400)
y = stats.norm.pdf(x, mu, sd)
fig, ax = plt.subplots(figsize=(9, 3.8))
ax.plot(x, y, color="#111827")
for k, c in [(3, "#e0e7ff"), (2, "#a5b4fc"), (1, "#6366f1")]:
    m = (x >= mu - k * sd) & (x <= mu + k * sd)
    ax.fill_between(x[m], y[m], color=c, label=f"±{k} SD = {stats.norm.cdf(k) - stats.norm.cdf(-k):.1%}")
ax.set_title("Delivery time ~ Normal(30, 5): the 68-95-99.7 rule"); ax.set_xlabel("minutes"); ax.legend()
plt.show()
Normal curve with shaded 1, 2 and 3 standard deviation bands
68% within 25–35 min, 95% within 20–40 min, 99.7% within 15–45 min.
Python
from scipy import stats
D = stats.norm(30, 5)
print("P(delivery > 40 min) =", round(1 - D.cdf(40), 4))
print("P(25 to 35 min)      =", round(D.cdf(35) - D.cdf(25), 4))
print("Promise time covering 95% of orders:", round(D.ppf(0.95), 1), "min")
print("Promise time covering 99% of orders:", round(D.ppf(0.99), 1), "min")
P(delivery > 40 min) = 0.0228 P(25 to 35 min) = 0.6827 Promise time covering 95% of orders: 38.2 min Promise time covering 99% of orders: 41.6 min
MethodQuestion it answers
pmf(k) / pdf(x)How likely is exactly k? / density at x
cdf(x)P(X ≤ x)
sf(x) = 1 − cdf(x)P(X > x)
ppf(q)Which value has q of the data below it? (inverse cdf)
rvs(size)Generate random samples

Is my data normal?

Python
import pandas as pd
import matplotlib.pyplot as plt
from scipy import stats
st = pd.read_csv("students_performance.csv")
s = pd.read_csv("sales_data.csv")
fig, ax = plt.subplots(1, 2, figsize=(10, 3.8))
stats.probplot(st["average"], dist="norm", plot=ax[0]); ax[0].set_title("Student averages – close to normal")
stats.probplot(s["unit_price"], dist="norm", plot=ax[1]); ax[1].set_title("Unit prices – strongly skewed")
plt.tight_layout(); plt.show()
print("Shapiro p (students, n=500):", round(stats.shapiro(st["average"]).pvalue, 3))
Shapiro p (students, n=500): 0.111
Q-Q plots of student averages (straight) and unit prices (curved)
Points on the red line = normal. A curve = skewed data.
🧠 Why care?

Many tests (t-test) and models (linear regression residuals) assume normality. Skewed data like prices is often log-transformed: np.log(price) is usually much closer to normal.

Real example: delivery promise from real-like data

Python
import numpy as np
from scipy import stats
rng = np.random.default_rng(3)
times = np.round(rng.normal(32, 6, 1000), 1)          # last month's delivery times
mu, sd = times.mean(), times.std(ddof=1)
promise = stats.norm(mu, sd).ppf(0.9)
print(f"Fitted Normal: mean={mu:.1f} sd={sd:.1f}")
print(f"Promise “in {np.ceil(promise):.0f} minutes” → on time for {np.mean(times <= np.ceil(promise)) * 100:.1f}% of orders (actual)")
Fitted Normal: mean=32.2 sd=6.0 Promise “in 40 minutes” → on time for 89.8% of orders (actual)

🏅 Job skills unlocked today

✔ Pick binomial, Poisson or normal for a problem✔ Compute probabilities with pmf/pdf/cdf/sf✔ Find thresholds with ppf✔ Check normality with Q-Q plots

Practice tasks

🏋️ Practice – do it yourself

Task 1: A restaurant gets 4 Zomato orders per 10 minutes on average. What is P(more than 7 orders in 10 minutes)?
Show solution
Python
from scipy import stats
print(round(stats.poisson(4).sf(7), 4))
0.0511
Task 2: A quiz has 10 MCQs with 4 options. If a student guesses everything, what is P(at least 5 correct)?
Show solution
Python
from scipy import stats
print(round(stats.binom(10, 0.25).sf(4), 4))
0.0781
Task 3: Heights of adult men are ~ Normal(170, 7) cm. What height is the 95th percentile? What share is above 185 cm?
Show solution
Python
from scipy import stats
H = stats.norm(170, 7)
print(round(H.ppf(0.95), 1), "cm |", round(H.sf(185) * 100, 2), "%")
181.5 cm | 1.61 %

Quick quiz

🧠 Quick Quiz – test yourself

1. Number of defective items in a batch of 50 (each 2% chance) follows…
Fixed n tries, each success/fail.
2. Number of website errors per hour is best modelled by…
Events at a rate over time.
3. In a normal distribution about 95% lies within…
68-95-99.7 rule.
4. stats.norm(30, 5).ppf(0.9) gives…
ppf is the inverse of cdf.
5. For Poisson with λ = 9, the variance is…
Mean = variance = λ.

Interview corner

💼 Interview Corner

When is the normal distribution a bad assumption?

For skewed or bounded data – incomes, prices, waiting times, counts near zero, or data with heavy tails (returns, insurance claims). Check with a histogram/Q-Q plot and consider log transforms or other distributions.

Binomial vs Poisson?

Binomial counts successes in a fixed number of trials n with probability p. Poisson counts events in an interval with no fixed n. For large n and small p, Binomial(n, p) ≈ Poisson(n·p).

Summary

  • Binomial: successes in n tries. Poisson: events per interval. Normal: measurements around a mean.
  • cdf for “at most”, sf for “more than”, ppf for thresholds.
  • 68-95-99.7 gives quick normal estimates.
  • Check normality before using tests that assume it.
➡️ Next

Day 29: sampling, the Central Limit Theorem and confidence intervals – how a survey of 1,000 can describe a city.

Frequently Asked Questions

Why is P(X = 30.0 minutes) zero for a normal distribution?
For continuous variables there are infinitely many exact values; probability is only meaningful for ranges like 29.5–30.5.
Do I need to memorise formulas?
No – scipy.stats computes them. Understand what each distribution models and which method answers your question.
← Data Science (60 Days)
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

Next topicDay 29: Sampling, CLT & Confidence Intervals Your progress: 28 / 60 (47%) · Lesson 29 / 60 Continue →

How was this lesson?

Your feedback helps us make the content better.

Write a review or suggestion (optional)

After approval, your name and city may appear publicly with your review. Please do not write your email or phone number.

▶ CodingEasily on YouTube

Learn with video lessons in easy Hindi

Featured video: RDBMS Part 3 – Class XI Commerce IT

▶ Subscribe – it’s free