Distributions and Bayes' Theorem
Lab 1: Distributions and Bayes' Theorem
Probability becomes intuitive when you can sample from distributions and watch the theory materialize in histograms. This lab takes the core results from r1–r3 — PMFs, PDFs, joint distributions, the law of total probability, and Bayes' theorem — and makes them concrete in NumPy and SciPy.
What You'll Build
- A PMF and PDF explorer: plot the Bernoulli, Poisson, Uniform, and Gaussian distributions side-by-side; verify normalization by integrating the PDF and summing the PMF
- A CDF calculator: compute and plot CDFs for continuous and discrete RVs; use to answer interval probability questions
- A joint distribution sampler: generate pairs from a 2D Gaussian, scatter-plot them, recover marginals by collapsing one axis, and compare to the theoretical marginal
- A law of total probability verifier: recreate the binary classifier error-rate calculation from q1 () with simulation, confirming the analytic result
- A Bayes' theorem sensitivity sweep: implement the disease-screening posterior as a function of the prior , plot over a range of priors from 0.001 to 0.5, and observe how the base-rate fallacy weakens as prevalence rises
Key Concepts Practiced
By the end you will see why PDF values are not probabilities, why the base-rate fallacy is structurally inevitable at low prevalence, and how marginalization is literally summation or integration over the unwanted variable.