CH 23Phase 3 · Probability & Statistics for AI

Probability Distributions

১৫–২৫ মিনিট বাংলা · Math · Python
📖 একটি ছোট গল্প

মানুষের উচ্চতা plot করলে bell-shape পাওয়া যায়। একদিনে রাস্তায় চলা গাড়ির সংখ্যা Poisson-এর মতো দেখায়। Spam vs not-spam একটি Bernoulli। Distribution = data-র "fingerprint" — সঠিক distribution চিনলে অর্ধেক ML কাজ শেষ।

Bernoulli & Binomial

Bernoulli(p)

একবার trial-এ success (1) বা failure (0)। P(X=1) = p

E[X] = p, Var(X) = p(1−p)

Binomial(n, p)

n বার independent Bernoulli trial-এ success-এর সংখ্যা।

P(X = k) = C(n,k) · pk · (1−p)n−k
E[X] = np, Var(X) = np(1−p)

Poisson(λ)

একটি নির্দিষ্ট সময়/স্থানে rare event-এর সংখ্যা। λ = average rate।

P(X = k) = e−λ · λk / k!
E[X] = λ, Var(X) = λ

উদাহরণ: ১ ঘণ্টায় call center-এ আসা call, একটি page-এ typo, একটি neighborhood-এ accident।

Normal (Gaussian) N(μ, σ²)

সবচেয়ে গুরুত্বপূর্ণ continuous distribution।

f(x) = (1 / σ√(2π)) · exp(−(x−μ)² / 2σ²)
E[X] = μ, Var(X) = σ²

68-95-99.7 rule

  • μ ± 1σ ভেতরে ~68% data
  • μ ± 2σ ভেতরে ~95% data
  • μ ± 3σ ভেতরে ~99.7% data
💡 ইনসাইট
Central Limit Theorem: যেকোনো distribution থেকে n sample-এর mean-এর distribution n বড় হলে normal হয়ে যায়। তাই Normal distribution AI-এ এত omnipresent।

Uniform, Exponential, Beta, Categorical

  • Uniform(a, b): equal probability সব value-এ — random init-এ ব্যবহার।
  • Exponential(λ): event-এর মধ্যে waiting time।
  • Beta(α, β): [0,1]-এ probability-র distribution — Bayesian prior।
  • Categorical / Multinomial: classifier output (softmax)।
  • Dirichlet: distribution over distribution — LDA topic model।

Python Implementation

pythonPython · NumPy
import numpy as np
from scipy import stats

# Bernoulli
b = stats.bernoulli(p=0.3)
print(f"Bernoulli(0.3):  mean={b.mean()}, var={b.var()}")

# Binomial: 10 coin flips, p=0.5
bin_ = stats.binom(n=10, p=0.5)
print(f"Binomial(10,0.5): P(X=5)={bin_.pmf(5):.4f}, mean={bin_.mean()}, var={bin_.var()}")

# Poisson: average 3 calls/hour
poi = stats.poisson(mu=3)
print(f"Poisson(3): P(X=2)={poi.pmf(2):.4f}, P(X≥5)={1-poi.cdf(4):.4f}")

# Normal
n = stats.norm(loc=0, scale=1)
print(f"Normal(0,1): P(-1≤X≤1)={n.cdf(1)-n.cdf(-1):.4f}")
print(f"            P(-2≤X≤2)={n.cdf(2)-n.cdf(-2):.4f}")

# Central Limit Theorem demo
np.random.seed(0)
# Take many samples of size 30 from uniform, look at mean distribution
sample_means = [np.random.uniform(0, 1, 30).mean() for _ in range(10_000)]
print(f"\nSample means: mean={np.mean(sample_means):.4f}, std={np.std(sample_means):.4f}")
print("→ Looks Normal even though source is Uniform!")

AI/ML সংযোগ

  • Logistic regression: Bernoulli likelihood maximize করে।
  • Softmax classifier: Categorical distribution।
  • VAE: latent space-এ Normal prior, reconstruction Gaussian likelihood।
  • Dropout: Bernoulli mask।
  • Diffusion model: Gaussian noise step-by-step add ও remove।
  • Reinforcement Learning: action sampling = Categorical distribution।

Common Mistakes

  • সব data-কে Normal ধরে নেওয়া — heavy-tailed (Cauchy, log-normal) data ভিন্ন।
  • Poisson-এ Var = Mean property miss করা — overdispersed data-তে Negative Binomial দরকার।
  • Binomial vs Poisson confusion — Poisson = Binomial-এর limit when n→∞, p→0, np=λ

Practice Tasks

  1. একটি coin (p=0.6) ১০০ বার toss-এ ৬০-৭০ head হওয়ার probability।
  2. একটি pizza shop-এ avg 5 order/hour। ৮ order আসার probability?
  3. Normal(170, 8)-এ একজন মানুষ 185+ cm উঁচু হওয়ার probability?

Assignment

একটি dataset (যেমন Boston Housing-এর "price" column) নিন। Histogram plot করুন। Normal, log-Normal, Exponential — কোন distribution best fit? Scipy-এর kstest দিয়ে goodness-of-fit verify করুন।

Interview Questions

  1. Central Limit Theorem কী বলে এবং AI-এ কেন গুরুত্বপূর্ণ?
  2. Poisson এবং Binomial-এর সম্পর্ক?
  3. কেন Normal distribution maximum entropy distribution (given mean, variance)?
  4. Beta distribution Bayesian inference-এ কেন popular?

Mini Project

"Distribution Fitter" — user CSV upload করে, tool automatic-ভাবে কয়েকটি distribution fit করে এবং AIC/BIC দিয়ে best fit suggest করে।

Summary · সারসংক্ষেপ

  • Distribution = data-র shape-এর গাণিতিক রূপ।
  • Bernoulli/Binomial = success-failure, Poisson = rare events, Normal = বহু-noise-এর sum।
  • Central Limit Theorem = কেন Normal everywhere।
  • প্রতিটি ML model কোনো না কোনো distributional assumption-এর উপর দাঁড়ানো।
✨ পরবর্তী পদক্ষেপ
Chapter 24-এ Statistics Fundamentals — mean, median, variance, covariance, এবং correlation।