Probability and Statistics · Discrete distributions
Bernoulli, binomial, geometric and Poisson distributions: what each one counts, their means, and computing them with scipy.stats.
| distribution | counts | parameters | mean |
|---|---|---|---|
| Bernoulli | one yes/no trial | p | p |
| Binomial | successes in n trials | n, p | np |
| Geometric | trials until the first success | p | 1/p |
| Poisson | events in a fixed interval | λ | λ |
Poisson is also the limit of Binomial(n, p) when n is large and p is small, with λ = np.
In scipy.stats, every distribution shares one interface: pmf (or pdf), cdf, sf (= 1 − cdf), mean, var, rvs (random samples).
from scipy import stats
b = stats.binom(n=10, p=0.3)
print("P(exactly 3 of 10) =", round(b.pmf(3), 4), "| P(at most 3) =", round(b.cdf(3), 4), "| mean", b.mean())
g = stats.geom(p=1 / 6)
print("P(first six on roll 4) =", round(g.pmf(4), 4), "| mean rolls", g.mean())
pois = stats.poisson(mu=4) # e.g. 4 emails per hour
print("P(0 emails) =", round(pois.pmf(0), 4), "| P(more than 6) =", round(pois.sf(6), 4))
big = stats.binom(n=1000, p=0.004) # Poisson approximation, lambda = 4
print("binomial vs poisson at k=2:", round(big.pmf(2), 5), round(pois.pmf(2), 5))
print("samples:", b.rvs(size=8, random_state=0))
Output:
P(exactly 3 of 10) = 0.2668 | P(at most 3) = 0.6496 | mean 3.0
P(first six on roll 4) = 0.0965 | mean rolls 6.0
P(0 emails) = 0.0183 | P(more than 6) = 0.1107
binomial vs poisson at k=2: 0.14638 0.14653
samples: [3 4 3 3 3 3 3 5]Sources
- scipy.stats.binom — SciPy
- scipy.stats.poisson — SciPy
- MIT 18.05 Reading 4b: Discrete distributions — MIT OpenCourseWare