A probability distribution describes how likely each value of a random variable is. Knowing the common distributions helps you model data, choose statistical tests and understand ML algorithms.
What You Will Learn
- Discrete vs continuous distributions
- Normal distribution and the 68-95-99.7 rule
- Binomial and Poisson distributions
- Uniform and exponential distributions
- Using scipy.stats: pmf, pdf, cdf and ppf
Prerequisites
Discrete vs Continuous
| Type | Values | Function | Examples |
|---|---|---|---|
| Discrete | Countable (0, 1, 2…) | PMF: P(X = k) | Binomial, Poisson |
| Continuous | Any value in a range | PDF; probability = area under the curve | Normal, uniform, exponential |
| scipy method | Gives |
|---|---|
pmf(k) / pdf(x) |
Probability (discrete) or density (continuous) at a point |
cdf(x) |
P(X ≤ x) |
ppf(q) |
Inverse of cdf: the value below which a fraction q lies (percentile) |
rvs(size) |
Random samples |
Normal Distribution
The bell curve, described by mean μ and standard deviation σ. Heights, measurement errors and exam marks are often roughly normal.
from scipy import stats
n = stats.norm(loc=70, scale=10) # marks ~ Normal(mean 70, sd 10)
print("P(X < 85):", round(n.cdf(85), 4))
print("P(60 < X < 80):", round(n.cdf(80) - n.cdf(60), 4))
print("90th percentile:", round(n.ppf(0.90), 2))
P(X < 85): 0.9332 P(60 < X < 80): 0.6827 90th percentile: 82.82
Explanation: About 68% of values lie within 1σ of the mean (60–80 here), 95% within 2σ and 99.7% within 3σ – the 68-95-99.7 rule. A student needs about 82.8 marks to be in the top 10%.
Binomial Distribution
Number of successes in n independent yes/no trials with success probability p.
b = stats.binom(n=10, p=0.5) # 10 coin tosses
print("P(exactly 7 heads in 10):", round(b.pmf(7), 4))
print("P(at most 3 heads):", round(b.cdf(3), 4))
P(exactly 7 heads in 10): 0.1172 P(at most 3 heads): 0.1719
Poisson Distribution
Number of events in a fixed interval when they happen at an average rate λ: calls per hour, website errors per day.
p = stats.poisson(mu=4) # on average 4 calls per hour
print("P(exactly 2 calls):", round(p.pmf(2), 4))
print("P(more than 6 calls):", round(1 - p.cdf(6), 4))
P(exactly 2 calls): 0.1465 P(more than 6 calls): 0.1107
Uniform and Exponential
u = stats.uniform(0, 10) # any value 0-10 equally likely
print("Uniform P(X<3):", u.cdf(3))
e = stats.expon(scale=5) # average wait 5 minutes
print("Exponential P(wait > 10 min):", round(1 - e.cdf(10), 4))
Uniform P(X<3): 0.3 Exponential P(wait > 10 min): 0.1353
Explanation: The exponential distribution models waiting time between Poisson events; with an average of 5 minutes, there is about a 13.5% chance of waiting more than 10.
Distributions in ML
| Distribution | Where you meet it |
|---|---|
| Normal | Feature scaling, linear-regression errors, weight initialisation |
| Bernoulli / binomial | Binary classification, logistic regression |
| Poisson | Count data (Poisson regression) |
| Uniform | Random initialisation, random search |
| Categorical / softmax | Multi-class outputs and LLM next-token choice |
Series
Maths & Statistics series: Descriptive Statistics · Probability · Statistical Distributions · Inferential Statistics · Hypothesis Testing · Linear Algebra · Calculus
Interview Questions
Q: PDF vs CDF?
The PDF gives density at a point; the CDF gives the probability of being at or below a value.
Q: When to use Poisson?
For counts of events in a fixed time or space at a constant average rate.
Practice Exercises
- If heights ~ Normal(165, 8), what share of people are taller than 180 cm?
- A shop gets 3 complaints a day on average. What is P(no complaints)?
Summary
Discrete distributions (binomial, Poisson) count events; continuous ones (normal, uniform, exponential) model measurements and times. scipy.stats gives pmf/pdf, cdf, ppf and random samples for all of them.
Next: Inferential Statistics
Machine Learning Tutorials, Courses and Certifications