পাঠ ২৪ · ৩০-এর মধ্যে · মডিউল ৩
Home / AI Courses / AI Foundations / পরিসংখ্যান ML-এর জন্য

ML-এর জন্য পরিসংখ্যান — অনুমান ও পরীক্ষা

Statistics for ML — estimation & testing
১০ মিনিট পড়া মাঝারি · Intermediate Python কোডসহ

এই পাঠে যা শিখবেন

  • MLE (Maximum Likelihood Estimation) — মডেল কীভাবে "শেখে"
  • MAP — Bayesian দৃষ্টি, prior যোগ করা
  • Confidence Interval — অনুমানের অনিশ্চয়তা পরিমাপ
  • Hypothesis Testing ও p-value — সিদ্ধান্ত নেওয়া
  • Bootstrap — sample থেকেই অনিশ্চয়তা বের করা

১ · পরিসংখ্যান ও ML — একই কয়েন

একজন পরিসংখ্যানবিদ ও একজন ML প্রকৌশলী প্রায়শই একই কাজ করেন — শুধু ভাষা ভিন্ন। দু'জনেই ডেটা থেকে নিদর্শন (পরিসংখ্যানে: parameter, ML-এ: weights) অনুমান করেন।

  • পরিসংখ্যান: ব্যাখ্যা ও অনুমান গুরুত্বপূর্ণ। "Coefficient সঠিক?", "বিতরণ Gaussian কি?"
  • ML: প্রায়ই পূর্বাভাসে দক্ষতা বেশি গুরুত্বপূর্ণ। "Test accuracy কত?"

কিন্তু গণিত — অনেকটাই অভিন্ন। MLE হলো সেতু — Andrew Ng-র ভাষায়, "ML is statistics with computers"।

২ · MLE — Maximum Likelihood Estimation

মূল ধারণা

ডেটা $D$ আছে। আমাদের মডেলের প্যারামিটার $\theta$। কোন $\theta$-তে এই ডেটা আসা সবচেয়ে সম্ভাব্য? $$\theta_{\text{MLE}} = \arg\max_\theta P(D \mid \theta)$$

সরল উদাহরণ — মুদ্রার পক্ষপাত অনুমান

একটি মুদ্রা ১০ বার ছুড়ে ৭ বার Heads পেলেন। Heads-এর সম্ভাবনা $p$ কত হবে অনুমান করুন।

$L(p) = \binom{10}{7} p^7 (1-p)^3$
log নিয়ে ডেরিভেটিভ ০ করলে — $p_{MLE} = \dfrac{7}{10} = 0.7$।

সরাসরি অভিজ্ঞতাজাত অনুপাত! সাধারণ intuition — কিন্তু গাণিতিকভাবে justified.

AI-এ MLE

Cross-entropy loss minimize করা = log-likelihoodLikelihood"ডেটা দিয়ে parameter কতটা probable" — না, "parameter দিয়ে ডেটা কতটা probable"। $L(\theta) = P(D|\theta)$। MLE — likelihood maximize, MAP — likelihood × prior maximize. maximize করা। অর্থাৎ — সব classification ML আসলে MLE. বিভিন্ন ভাষায় একই গণিত।

৩ · MAP — Maximum A Posteriori

MLE-তে শুধু ডেটা ব্যবহার হয়। MAP-এ Bayesian দৃষ্টিতে — prior (পূর্ব-জ্ঞান)-ও যোগ হয়:

$$\theta_{\text{MAP}} = \arg\max_\theta \big[\, P(D \mid \theta) \cdot P(\theta) \,\big]$$

উদাহরণ — মুদ্রায় ৭/১০

MLE বলবে $p = 0.7$। কিন্তু আপনি জানেন — মুদ্রা সাধারণত প্রায় ভারসাম্যপূর্ণ। তাই "$p$ ০.৫-এর কাছাকাছি" — এই prior দিয়ে MAP-এ $p$ আসবে যেমন $0.6$।

AI-এ MAP

Regularization (L2/L1) আসলে MAP-এর একটি রূপ। L2 = "weights ছোট হওয়া উচিত" — এটাই Gaussian prior. L1 = "weights sparse হওয়া উচিত" — এটাই Laplace prior. মানে — যখন আপনি weight decay চালু করেন, আপনি Bayesian inference-ই করছেন (অজান্তে)।

৪ · Sample MeanSample Mean · নমুনা গড়$\bar{x} = \frac{1}{n}\sum x_i$ — পুরো population না দেখে কিছু sample-এর গড়। প্রকৃত population mean ($\mu$)-এর অনুমান। ও Standard ErrorStandard Error (SE)একটি sample statistic-এর অনিশ্চয়তা — $SE = \sigma/\sqrt{n}$। বেশি sample = ছোট SE = বেশি নিশ্চিত অনুমান।

একটি জনসংখ্যার গড় ($\mu$) জানতে চাই। কিন্তু সম্ভব না — একটি sample $\{x_1, ..., x_n\}$ নিয়ে কাজ করি।

Sample mean: $\bar{x} = \dfrac{1}{n} \sum x_i$
Standard error: $SE = \dfrac{\sigma}{\sqrt{n}}$ — এই অনুমানের অনিশ্চয়তা।

SE ছোট মানে বেশি নিশ্চিত। বেশি sample = ছোট SE. কিন্তু $\sqrt{n}$ — তাই ১০x sample মানে ৩.১৬x ভাল precision, ১০x না।

৫ · Confidence Interval

সরাসরি একটা সংখ্যা দেওয়ার বদলে — একটি ব্যাপ্তি দিন: "আমি ৯৫% নিশ্চিত মান এই ব্যাপ্তিতে।"

৯৫% CI সূত্র

$\text{CI}_{95\%} = \bar{x} \pm 1.96 \cdot SE$

$1.96$ আসে Gaussian-এর ৯৫% নিয়ম থেকে (পাঠ ১৭)। ৯৯% CI চাইলে $2.576$, ৯০% হলে $1.645$।

AI-এ ব্যবহার

  • একটি মডেলের accuracy ৮৫.৩% — কিন্তু ৯৫% CI: $[83.1\%, 87.5\%]$।
  • দু'টি মডেলের CI overlap করলে — পার্থক্যটি statistically significant নয়।
  • Paper-এ "model A 87%, model B 88%" — CI ছাড়া অর্থহীন।

৬ · Hypothesis TestingHypothesis Testing · অনুমান পরীক্ষাএকটি দাবি (যেমন "নতুন মডেল ভাল") ডেটার ভিত্তিতে পরীক্ষা করার গাণিতিক পদ্ধতি — null hypothesis সাজিয়ে p-value হিসেব। — সিদ্ধান্ত নেওয়া

নতুন একটি AI মডেল আগেরটার চেয়ে কি সত্যিই ভালো? — এই ধরনের প্রশ্নের উত্তর hypothesis testing-এ।

পদ্ধতি

  1. Null hypothesisNull Hypothesis ($H_0$)"কিছুই ঘটছে না/পার্থক্য নেই" — যে দাবি reject করার চেষ্টা করা হয়। ডেটা $H_0$-এর বিরুদ্ধে যথেষ্ট সাক্ষ্য দিলে আমরা $H_0$ বাতিল করি। ($H_0$): "কোনো পার্থক্য নেই।"
  2. Alternative ($H_1$): "নতুন মডেল ভালো।"
  3. ডেটা থেকে একটি statistic হিসাব।
  4. p-value: $H_0$ সত্য হলে এই statistic বা আরও চরম দেখার সম্ভাবনা।
  5. $p < 0.05$ — $H_0$ reject (পার্থক্য significant)।
p-value মানে কী না: "$p < 0.05$" মানে "${ }H_0$ ৫% সত্য" নয়। এটি বলে — যদি $H_0$ সত্য হতো, এই ফল দেখার সম্ভাবনা কম। ভুল ব্যাখ্যায় বহু বিজ্ঞান কেলেঙ্কারি হয়েছে। American Statistical Association ২০১৬-তে এই ভুল ব্যাখ্যার বিরুদ্ধে formal statement প্রকাশ করেছিল।

৭ · Python-এ Statistics

Python · Confidence Interval
import numpy as np

np.random.seed(42)

# একটি AI মডেলের accuracy ১০ বার পরীক্ষা
accuracies = np.array([0.852, 0.861, 0.847, 0.858, 0.853,
                       0.849, 0.864, 0.851, 0.855, 0.860])

n = len(accuracies)
mean = accuracies.mean()
std = accuracies.std(ddof=1)   # sample std (ddof=1)
se = std / np.sqrt(n)

# 95% CI
ci_low = mean - 1.96 * se
ci_high = mean + 1.96 * se

print(f"গড় accuracy: {mean:.4f}")
print(f"Standard Error: {se:.4f}")
print(f"95% CI: [{ci_low:.4f}, {ci_high:.4f}]")
print(f"\nঅর্থ: আমরা ৯৫% নিশ্চিত — মডেলের প্রকৃত accuracy")
print(f"      {ci_low*100:.2f}% থেকে {ci_high*100:.2f}%-এর মধ্যে।")

    
মাত্র ১০টি পরিমাপের ভিত্তিতে — আমরা সঠিকভাবে অনিশ্চয়তা প্রকাশ করছি। বাস্তব AI পরীক্ষায় এটি অপরিহার্য।
ML Statistics — অনুমানের যাত্রা From data to decisions, with uncertainty Data D = {x₁, x₂, ..., xₙ} Sample from population MLE θ_MLE = argmax P(D|θ) "যা ডেটা explain করে" MAP θ_MAP = argmax P(D|θ)·P(θ) "ডেটা + prior knowledge" Point estimate θ̂ but how certain? Confidence Interval θ̂ ± 1.96 · SE (95% CI) analytical (Gaussian) or bootstrap (universal) Hypothesis Test → p-value → "significant?" decision
ডেটা থেকে decision-এ পৌঁছানোর গাণিতিক পথ। MLE (data alone) বা MAP (data + prior) → point estimate → CI → hypothesis test. প্রতিটি AI experiment-এ এই pipeline.

৮ · Bootstrap — পুনঃনমুনায়ন কৌশল

Bootstrap একটি জাদুকর কৌশল — sample থেকেই sample নিয়ে অনিশ্চয়তা মাপা। সূত্রের প্রয়োজন নেই। Bradley Efron ১৯৭৯-তে আবিষ্কার করেন — পরিসংখ্যানের ২০ শতকের সবচেয়ে গুরুত্বপূর্ণ আবিষ্কারগুলোর একটি।

পদ্ধতি

  1. আপনার $n$টি ডেটা-পয়েন্ট আছে।
  2. $n$টি ডেটা-পয়েন্ট প্রতিস্থাপনসহ তুলুন (অর্থাৎ একই point একাধিকবার আসতে পারে)।
  3. এই নতুন sample-এ statistic হিসাব করুন।
  4. হাজার বার পুনরাবৃত্তি করুন।
  5. সংগৃহীত হাজার statistic-এর বিতরণ থেকে CI বের করুন।
Python · Bootstrap CI
import numpy as np

np.random.seed(42)
data = np.array([0.852, 0.861, 0.847, 0.858, 0.853,
                 0.849, 0.864, 0.851, 0.855, 0.860])

# 10,000 bootstrap sample
n_boot = 10000
boot_means = []
for _ in range(n_boot):
    sample = np.random.choice(data, size=len(data), replace=True)
    boot_means.append(sample.mean())

boot_means = np.array(boot_means)

# Percentile-ভিত্তিক CI
ci_low = np.percentile(boot_means, 2.5)
ci_high = np.percentile(boot_means, 97.5)

print(f"Bootstrap গড়: {boot_means.mean():.4f}")
print(f"Bootstrap 95% CI: [{ci_low:.4f}, {ci_high:.4f}]")

    
Bootstrap CI সূত্র-ভিত্তিক CI-এর সাথে কাছাকাছি — কিন্তু কোনো অনুমানের প্রয়োজন ছিল না (যেমন Gaussian)। যেকোনো statistic-এর জন্য কাজ করে — median, max, ratio.

৯ · AI-তে কোথায় এই সব?

  • Model evaluation: Accuracy point estimate — CI ছাড়া অর্থহীন।
  • A/B testing: দু'টি AI সিস্টেমের তুলনা — t-test বা bootstrap.
  • MLE: প্রায় সব ML training (cross-entropy = -log-likelihood)।
  • Regularization: MAP-এর বিভিন্ন রূপ — L2 (Gaussian), L1 (Laplace)।
  • Bayesian Deep Learning: মডেলের নিজের অনিশ্চয়তা পরিমাপ।
  • Bootstrap: Ensemble methods (Bagging, Random Forest)-এর গাণিতিক ভিত্তি।
  • Cross-validation: Model performance-এর CI.
ML একটি শাখা — কিন্তু পরিসংখ্যান-এর গভীর শিকড়ে। যিনি দু'টোই বুঝেন — তিনি অনেক বেশি কার্যকর AI প্রকৌশলী হবেন। একটি interview-এ "your model has 87% accuracy" বললে অনভিজ্ঞ; "87% ± 2.3% (95% CI, n=১০ runs)" — পেশাদার।

১০ · এক বাক্যে

"MLE = data fit. MAP = data fit + prior. CI = অনিশ্চয়তা। p-value = সাবধানে! Bootstrap = সর্বজনীন সমাধান।"

ভাবনার প্রশ্ন

প্রতিটি প্রশ্ন নিজে কিছুক্ষণ ভাবুন — তারপর "→ উত্তর" চাপুন।

প্র ০১ "Frequentist vs Bayesian" — দু'টি statistics-এর philosophical war ১০০ বছরের। ML-এ আসলে কোনটি ব্যবহৃত? দু'টোর মধ্যে আজকের বাস্তব মিশ্রণ কী?

এটি statistics-এর সবচেয়ে interesting historical debate. ১৯২০-৫০-এ Fisher, Neyman, Pearson — frequentist; Jeffreys, Bayes-এর shadow — Bayesian. ML এই বিভাজনকে partly transcend করেছে।

(১) Frequentist দর্শন:

  • Probability = long-run frequency.
  • Parameter $\theta$ — fixed but unknown.
  • Data — random.
  • Hypothesis test, confidence interval, p-value — frequentist tools.
  • "Given infinite data, how often I'd be right?"

(২) Bayesian দর্শন:

  • Probability = degree of belief.
  • Parameter $\theta$ — random with distribution.
  • Prior + likelihood = posterior (Bayes' theorem)।
  • "Given my data, what's my belief about parameters?"

(৩) ML-এ কোনটা?

  • Surprisingly mixed:
  • Cross-entropy loss = MLE → frequentist root.
  • L2 regularization = Gaussian prior → Bayesian root.
  • Dropout = approximate Bayesian inference.
  • VAE, BNN — explicitly Bayesian.
  • Deep learning practitioners use both, often unknowingly.

(৪) কখন কোনটা practical?

  • Frequentist (large data): A/B testing, classical ML — sample size বড় হলে dominant.
  • Bayesian (small data, prior knowledge): Drug trials, expert systems.
  • Bayesian (uncertainty quantification): Active learning, safety-critical AI.

(৫) আজকের bridge — Empirical Bayes:

  • Prior data থেকেই estimate.
  • Hierarchical models — Bayesian framework, frequentist parameter estimation.
  • Stein's paradox — অনেক parameter একসাথে estimate করলে — Bayesian shrinkage ভাল।

(৬) Deep Learning-এ:

  • Standard NN: Frequentist (point estimate)।
  • BNN (Bayesian NN): Weight-এর posterior.
  • MC Dropout (Gal & Ghahramani ২০১৬): Dropout = Bayesian inference.
  • Deep Ensembles: Approximate Bayesian, easier.
  • Conformal Prediction: Frequentist uncertainty quantification.

(৭) Real-world implications:

  • Medical AI — Bayesian preferred (uncertainty critical)।
  • Self-driving cars — Bayesian uncertainty for safety.
  • Recommendation — frequentist (huge data)।
  • RLHF — Bayesian-ish KL constraints.

(৮) Bangladesh context:

  • Small data scenarios — Bayesian critical.
  • Bangla NLP-এ pre-trained model + small fine-tune = Bayesian flavor.
  • Medical diagnosis app — Bayesian uncertainty mandatory.

মূল উপলব্ধি: Frequentist vs Bayesian — অর্ধশতক ধরে statistics-এর "religion war"। আজকের ML practical — দু'টিই ব্যবহার, প্রায় unconsciously. ভাল ML engineer দু'টির philosophical foundation বুঝে — সঠিক problem-এ সঠিক approach.

প্র ০২ "L2 regularization = Gaussian prior" — এই connection ML-এ ঘন ঘন উল্লিখিত। গাণিতিকভাবে কীভাবে derive করা যায়? কেন এটি practitioners-এর জন্য গুরুত্বপূর্ণ?

এই connection ML-এর সবচেয়ে elegant theoretical insights-এর একটি। Linear regression থেকে deep learning পর্যন্ত প্রায় সব অংশে এর প্রতিফলন।

(১) Setup:

  • Linear regression: $y = w^T x + \epsilon$, $\epsilon \sim N(0, \sigma^2)$।
  • Weights $w$ on prior: $w \sim N(0, \tau^2 I)$ (Gaussian, mean 0)।
  • Goal: posterior $P(w | D) = \dfrac{P(D|w) P(w)}{P(D)}$।

(২) Likelihood:

$P(D|w) = \prod_i N(y_i | w^T x_i, \sigma^2) \propto \exp\left(-\dfrac{1}{2\sigma^2}\sum_i (y_i - w^T x_i)^2\right)$

(৩) Prior:

$P(w) = N(0, \tau^2 I) \propto \exp\left(-\dfrac{1}{2\tau^2} \|w\|^2\right)$

(৪) MAP — log নিয়ে:

$\log P(w|D) = -\dfrac{1}{2\sigma^2}\sum_i (y_i - w^T x_i)^2 - \dfrac{1}{2\tau^2}\|w\|^2 + \text{const}$

$\arg\max$ = $\arg\min$ of negative:

$\hat{w} = \arg\min_w \left[\sum_i (y_i - w^T x_i)^2 + \dfrac{\sigma^2}{\tau^2}\|w\|^2\right]$

সরাসরি ridge regression! $\lambda = \sigma^2/\tau^2$ — regularization strength.

(৫) তাৎপর্য:

  • $\tau$ ছোট = strong prior (weights small) = $\lambda$ বড় (more regularization)।
  • $\tau$ বড় = weak prior = $\lambda$ ছোট = closer to MLE.
  • $\tau \to \infty$: pure MLE.

(৬) L1 regularization?

  • L1 = Laplace prior: $P(w) \propto \exp(-|w|/b)$।
  • Sharp peak at 0 → sparse weights.
  • "Most weights are exactly zero" prior.

(৭) Practical implications:

  • Hyperparameter বুঝা: $\lambda$ — শুধু "magic number" না, prior-এর strength.
  • Bayesian interpretation: Cross-validation $\lambda$ tuning = empirical Bayes.
  • Calibrated regularization: Domain knowledge থেকে $\tau$ estimate.
  • Group LASSO, Elastic Net: বিভিন্ন priors.

(৮) Deep learning-এ:

  • Weight decay (L2) = Gaussian prior on every weight.
  • Dropout = stochastic regularization, approximate Bayesian.
  • Batch norm = implicit regularization.
  • Early stopping = posterior-এর "neighborhood" থেকে stop.

(৯) Beyond Gaussian — Bayesian Deep Learning:

  • Variational Inference: explicit posterior approximation.
  • MC Dropout: dropout = posterior sampling.
  • SWAG: SGD trajectory থেকে posterior approximate.
  • Deep Ensembles: multiple models = posterior samples.

(১০) Bangladesh AI context:

  • Limited data (Bangla datasets ছোট) — strong prior valuable.
  • Pre-trained model fine-tuning — pretrained weights = prior.
  • Domain expertise (medical, legal Bangla) — explicit prior helps.

মূল উপলব্ধি: "L2 regularization = Gaussian prior" — শুধু trick না, statistics-এর deep insight. এই connection বুঝলে — hyperparameter tuning informed, regularization interpretable, model uncertainty meaningful. Mature ML engineer-এর mathematical literacy এখানে।

প্র ০৩ p-value এবং AI evaluation: একটি new model-এর accuracy ৮৭%, baseline ৮৫%। এটি "significant improvement"? কীভাবে test করব? কী কী ভুল হতে পারে?

AI evaluation-এ p-value misuse epidemic. Tech blog-এ "model improved by 2%" claims-এর পেছনে প্রায়ই কোনো statistical test নেই। সঠিক approach critical.

(১) Naive comparison সমস্যা:

  • "৮৭% vs ৮৫% — তাই ভাল।" — কিন্তু variance?
  • Single test set-এর performance noise হতে পারে।
  • Different random seeds = different results.
  • Cherry-picking risk.

(২) সঠিক methodology:

  1. Multiple runs: দু'টি model 10-50 বার train, ভিন্ন seeds.
  2. Same test set: Paired comparison.
  3. Paired t-test: Per-seed difference Gaussian হলে।
  4. Wilcoxon signed-rank test: Non-parametric, robust.
  5. Bootstrap: Distribution-free CI.
  6. McNemar's test: Per-sample classification difference.

(৩) Python example:

from scipy.stats import ttest_rel, wilcoxon

baseline = [0.847, 0.851, 0.849, 0.852, 0.850, ...]  # 10 runs
new_model = [0.866, 0.871, 0.869, 0.872, 0.868, ...]  # 10 runs

# Paired t-test
t, p = ttest_rel(new_model, baseline)
print(f"t={t:.3f}, p={p:.4f}")
# p < 0.05 হলে "significant" claim করা যায়

(৪) Common ভুল:

  • "p-value = probability that $H_0$ is true":
    • ভুল! p-value = $P(\text{data} | H_0)$, not $P(H_0 | \text{data})$।
  • "p > 0.05 = no difference":
    • ভুল! Power-এর সমস্যা — small sample-এ significant difference miss.
  • "p-hacking":
    • একাধিক test, multiple comparisons — Bonferroni correction.
    • Until significant — fishing expedition.
  • "Significant = practically important":
    • Statistical significance ≠ effect size. 0.001% improvement statistically significant হতে পারে কিন্তু useless.

(৫) Effect size — p-value-এর companion:

  • Cohen's d: $(\mu_1 - \mu_2) / \sigma$।
  • $d < 0.2$: small, $0.5$: medium, $> 0.8$: large.
  • "Significant + meaningful effect size" — দু'টোই দরকার।

(৬) Multiple testing problem:

  • ২০টি hyperparameter try করলে — $5\%$ false positive accidental.
  • Solution: Bonferroni ($\alpha/k$), Benjamini-Hochberg (FDR)।
  • Hyperparameter sweep-এ সাবধান।

(৭) Bayesian alternative:

  • Bayes Factor: $P(D|H_1) / P(D|H_0)$।
  • "How much more likely is $H_1$?"
  • Direct probability, no $\alpha$।

(৮) Production-friendly checklist:

  • Document baseline accurately.
  • Multiple runs (≥10) — both models.
  • Same test set, no peeking.
  • Pre-register hypothesis (if research)।
  • Report mean ± std + CI + p-value + effect size.
  • Consider business impact, not just statistical.

(৯) Bangladesh tech context:

  • "AI startup achieved 95% accuracy on Bangla NER" — কোন test set?
  • Local benchmarks limited — hard to compare.
  • Sajek/IndicNLP datasets — standardize.

(১০) The "Statistical Crisis":

  • Replication crisis: many published findings can't be reproduced.
  • ML reproducibility crisis (NeurIPS, ICML)।
  • Solution: open-source code, multiple seeds, pre-registered analysis.

মূল উপলব্ধি: "Model A is better than Model B" — easy to claim, hard to prove. Real ML rigor — multiple seeds, pre-registered analysis, effect size, business validation. Senior ML engineer এই rigor maintain করেন — junior দের accuracy point comparison দিয়ে impress.

প্র ০৪ "Bootstrap" — সরল কিন্তু powerful trick. কেন এটি কাজ করে theoretically? কখন bootstrap fail করে? Real ML production-এ কোথায় ব্যবহার?

Bootstrap (Bradley Efron, ১৯৭৯) — modern statistics-এর সবচেয়ে important computational invention. সব evaluation-এ আজ default.

(১) মৌলিক ধারণা:

  • Population unknown — কিন্তু sample যথেষ্ট representative.
  • Sample-কে population-এর "approximation" ধরো।
  • Sample থেকে resample = "synthetic samples"।
  • প্রতিটিতে statistic compute → distribution.

(২) কেন কাজ করে — Glivenko-Cantelli theorem:

  • Empirical distribution function (ECDF) → true CDF, $n \to \infty$।
  • Bootstrap = sampling from ECDF.
  • $n$ যথেষ্ট হলে — bootstrap distribution ≈ sampling distribution.
  • Mathematical guarantee under regularity conditions.

(৩) Bootstrap variants:

  • Basic Bootstrap: Resample with replacement, compute statistic.
  • Percentile Bootstrap: Bootstrap distribution-এর 2.5%, 97.5% percentile = 95% CI.
  • BCa (Bias-Corrected and accelerated): Skewness adjustment.
  • Studentized Bootstrap: Better for small samples.
  • Block Bootstrap: Time series-এ — correlation preserve.

(৪) কখন fail করে:

  • Heavy-tailed distributions: Extreme values rare → bootstrap underestimate variance.
  • Small sample (n < 30): ECDF poor approximation.
  • Dependent data: Time series, spatial — naive bootstrap breaks.
  • Discrete extremes: Min/max-এর bootstrap distribution unstable.
  • Moment non-existent: Cauchy distribution-এর mean undefined.

(৫) Real ML production:

  • Model evaluation: Test set accuracy-এর CI.
  • Feature importance: Bootstrap permutation importance — Random Forest-এ।
  • Bagging (Bootstrap Aggregating): Random Forest-এর foundation. Breiman ১৯৯৬।
  • Hyperparameter sensitivity: Different bootstrap samples-এ best hyperparameter ভিন্ন? — instability indicator.
  • A/B testing: Conversion rate-এর CI.
  • Recommender system: Item ranking-এর uncertainty.
  • Calibration: Predicted probability-এর reliability.

(৬) Implementation tips:

def bootstrap_ci(data, statistic, n_boot=10000, alpha=0.05):
    boot_stats = []
    n = len(data)
    for _ in range(n_boot):
        sample = np.random.choice(data, size=n, replace=True)
        boot_stats.append(statistic(sample))
    boot_stats = np.array(boot_stats)
    lower = np.percentile(boot_stats, 100 * alpha / 2)
    upper = np.percentile(boot_stats, 100 * (1 - alpha / 2))
    return lower, upper

# Median CI
ci = bootstrap_ci(data, np.median)
print(f"Median 95% CI: {ci}")

(৭) Bootstrap-এর computational cost:

  • $n_{boot} = 10,000$ — adequate for percentile CI.
  • Parallel — embarrassingly parallel.
  • Modern CPU-এ ১ সেকেন্ডে done.
  • GPU-এ vectorize ১০x faster.

(৮) Bagging — bootstrap-এর জাদু:

  • Random Forest: $B$ bootstrap samples, প্রতিটিতে decision tree, vote/average.
  • Variance reduction. Bias same.
  • $B = 100-1000$ — typical.
  • Out-of-bag (OOB) error — built-in cross-validation.

(৯) Modern variants:

  • Bayesian bootstrap: Continuous weights instead of integer counts.
  • Wild bootstrap: Heteroskedastic regression.
  • Bootstrap aggregating in deep learning: Limited — too expensive.

(১০) Bangladesh ML scenarios:

  • Bangla sentiment dataset — small, noisy. Bootstrap CI critical.
  • BB টেস্ট ক্রিকেট data — bootstrap for player performance.
  • Pathao/Foodpanda A/B test — bootstrap for conversion lift.
  • SME loan default prediction — bootstrap importance ranking.

মূল উপলব্ধি: Bootstrap — সরল কিন্তু revolutionary. "Sample is the population in microcosm" — এই philosophical insight দিয়ে যেকোনো statistic-এর uncertainty বের। ১৯৭৯-এর invention আজকের ML production-এ default tool. Beautiful science, beautiful application.

অনুশীলন

  1. হিসাব করুন: ১৫ জন গ্রাহকের ক্রয়মূল্য (টাকা): $\{120, 150, 130, 200, 180, 175, 145, 160, 155, 190, 170, 140, 165, 155, 175\}$।
    • গড় ও standard error বের করুন।
    • ৯৫% CI কত?
    import numpy as np
    data = np.array([120, 150, 130, 200, 180, 175, 145, 160,
                     155, 190, 170, 140, 165, 155, 175])
    n = len(data)
    mean = data.mean()                # 160.67
    std = data.std(ddof=1)            # ~22.27
    se = std / np.sqrt(n)             # ~5.75
    ci = (mean - 1.96*se, mean + 1.96*se)  # (149.4, 171.9)
    print(f"mean={mean:.2f}, SE={se:.2f}, 95% CI={ci}")

    গড় ১৬০.৬৭, ৯৫% CI প্রায় [১৪৯.৪, ১৭১.৯]। অর্থ — population mean সম্ভবত এই ব্যাপ্তিতে।

  2. Bootstrap-এ চেষ্টা: উপরের ডেটায় bootstrap-এ মধ্যমান (median)-এর CI বের করুন।
    import numpy as np
    np.random.seed(42)
    data = np.array([120, 150, 130, 200, 180, 175, 145, 160,
                     155, 190, 170, 140, 165, 155, 175])
    
    n_boot = 10000
    boot_medians = [np.median(np.random.choice(data, size=len(data), replace=True))
                    for _ in range(n_boot)]
    ci_low  = np.percentile(boot_medians, 2.5)
    ci_high = np.percentile(boot_medians, 97.5)
    print(f"Median 95% CI: [{ci_low}, {ci_high}]")

    Median ১৬০, bootstrap 95% CI প্রায় [১৪৫, ১৭৫]। Median-এর CI সূত্র-ভিত্তিক না, তাই bootstrap অপরিহার্য।

  3. চিন্তা করুন: Model A: 95% accuracy, n=১০০ test. Model B: 96% accuracy, n=১০। কোনটি বেশি ভরসাযোগ্য? কেন?

    Model A বেশি ভরসাযোগ্য। Standard error $\propto 1/\sqrt{n}$।

    • Model A: $SE \approx \sqrt{0.95 \times 0.05/100} = 0.022$, ৯৫% CI ~ $[90.7\%, 99.3\%]$।
    • Model B: $SE \approx \sqrt{0.96 \times 0.04/10} = 0.062$, ৯৫% CI ~ $[83.8\%, 100\%]$।

    Model B-এর CI Model A-এর CI-কে ঢেকে রাখে — পার্থক্য significant না। Sample size matters.

আরও পড়ুন · ABCL TECH-এ আপনার পরবর্তী পদক্ষেপ

কোড রানার কাজ না করলে? ব্রাউজারে কাজ না করলে Google Colab ব্যবহার করুন — Google-এর ফ্রি অনলাইন Python পরিবেশ, শুধু Gmail অ্যাকাউন্ট লাগে।
পূর্ববর্তী পাঠ
পাঠ ২৩ · সংখ্যাগত স্থিরতা