Probability aur Distributions: Normal, Binomial aur CLT

Lesson 16 of 26

Probability kisi cheez ke hone ki sambhavna hai — 0 (kabhi nahi) se 1 (pakka) tak. Data Science me har prediction asal me ek probability hi hai: is customer ke churn karne ki 80% sambhavna hai.

Simulation se probability

Dice pe 6 aane ki probability 1/6 ≈ 0.167 hai. Chaliye 10,000 baar dice phenk ke dekhte hain:

Example

Python
import numpy as np

rng = np.random.default_rng(42)
rolls = rng.integers(1, 7, size=10_000)

print("6 aane ki probability (simulation):", (rolls == 6).mean())
print("Theory:", round(1 / 6, 4))

Output

Plain Text
6 aane ki probability (simulation): 0.1625
Theory: 0.1667

Do dice ka jod 7 aane ki probability (theory me 6/36):

Example

Python
dice1 = rng.integers(1, 7, size=100_000)
dice2 = rng.integers(1, 7, size=100_000)

print("Simulation:", ((dice1 + dice2) == 7).mean())
print("Theory:", round(6 / 36, 4))

Output

Plain Text
Simulation: 0.16816
Theory: 0.1667

Jitne zyada trials, simulation utna theory ke paas — isko Law of Large Numbers kehte hain.

Normal distribution

Height, exam marks, measurement errors — bahut saari cheezein bell curve jaisi hoti hain. Isko Normal distribution kehte hain, jo do cheezon se define hota hai: mean (μ) aur standard deviation (σ).

Example

Python
import matplotlib.pyplot as plt
from scipy.stats import norm

x = np.linspace(-4, 4, 200)
plt.plot(x, norm.pdf(x), color="#2563eb")
plt.fill_between(x, norm.pdf(x), where=(abs(x) <= 1), alpha=0.3, label="±1σ (68%)")
plt.title("Standard Normal Distribution")
plt.legend()
plt.show()

Standard normal distribution ki bell curve

68-95-99.7 rule

Example

Python
for k in [1, 2, 3]:
    inside = norm.cdf(k) - norm.cdf(-k)
    print(f"Mean ke ±{k} std ke andar: {inside:.4f}")

Output

Plain Text
Mean ke ±1 std ke andar: 0.6827
Mean ke ±2 std ke andar: 0.9545
Mean ke ±3 std ke andar: 0.9973

Yaani normal data me lagbhag 68% values mean ± 1 std me, 95% ± 2 std me, aur 99.7% ± 3 std me hoti hain.

Example: height

Maan lijiye logon ki height ka mean 165 cm aur std 7 cm hai. Kitne log 180 cm se lambe honge?

Example

Python
mean, std = 165, 7

p_taller = 1 - norm.cdf(180, loc=mean, scale=std)
print(f"180 cm se lambe: {p_taller:.4f}  (lagbhag {p_taller * 100:.1f}%)")
print("180 cm ka z-score:", round((180 - mean) / std, 2))
print("Top 10% ke liye kam se kam height:", round(norm.ppf(0.90, mean, std), 1))

Output

Plain Text
180 cm se lambe: 0.0161  (lagbhag 1.6%)
180 cm ka z-score: 2.14
Top 10% ke liye kam se kam height: 174.0

Binomial distribution

Jab ek kaam n baar ho, har baar sirf do result hon (success/fail), aur success ki probability p fixed ho. Jaise: 10 customers ko call kiya, har ek ke kharidne ki probability 30% hai:

Example

Python
from scipy.stats import binom

n, p = 10, 0.3
print("Theek 3 kharidein:", round(binom.pmf(3, n, p), 4))
print("Kam se kam 5 kharidein:", round(binom.sf(4, n, p), 4))
print("Average kitne kharidenge:", binom.mean(n, p))

Output

Plain Text
Theek 3 kharidein: 0.2668
Kam se kam 5 kharidein: 0.1503
Average kitne kharidenge: 3.0

Central Limit Theorem (CLT)

Statistics ka sabse powerful idea: population ka distribution kaisa bhi ho, agar hum baar-baar samples lekar unka mean nikaalein, to un means ka distribution normal hota hai. Isi wajah se hypothesis testing kaam karti hai.

Example

Python
# bahut skewed population: delivery time (exponential)
population = rng.exponential(scale=30, size=100_000)

sample_means = [rng.choice(population, size=50).mean() for _ in range(2000)]

fig, axes = plt.subplots(1, 2, figsize=(10, 4))
axes[0].hist(population, bins=50, color="#f97316")
axes[0].set_title("Population (skewed)")
axes[1].hist(sample_means, bins=40, color="#10b981")
axes[1].set_title("Sample means (normal!)")
plt.tight_layout()
plt.show()

print("Population mean:", round(population.mean(), 2))
print("Sample means ka mean:", round(np.mean(sample_means), 2))
print("Sample means ka std:", round(np.std(sample_means), 2),
      "| Theory σ/√n:", round(population.std() / np.sqrt(50), 2))

Output

Plain Text
Population mean: 29.85
Sample means ka mean: 29.64
Sample means ka std: 4.22 | Theory σ/√n: 4.24

CLT: skewed population aur sample means ka normal distribution

Probability aur distributions ko aur detail me padhna ho to ye guide dekhiye: Complete Probability & Distributions Guide.