The Binomial Distribution
Intuition
Flip a biased coin times. The number of heads is random; the binomial distribution says how likely each count is. Every count can happen in orders, each with the same probability.
Precise explanation
For independent trials with success probability :
Cumulative: . Tail: . Mean , variance . Values of outside have probability 0.
math.comb(n, k) gives the binomial coefficient (you implemented it in MA-07).
In Python 0 ** 0 == 1, which correctly handles or at the boundaries.
Worked example
, : . .
Common mistakes
- Forgetting the factor (computing one specific sequence).
- Computing as (off by one).
- Not validating .
Why this matters
Accuracy on a test set of examples is a binomial proportion; A/B tests, dropout masks (DL-21) and client participation (FL-08) are Bernoulli processes.
Library implementation
scipy.stats.binom(n, p) provides .pmf(k), .cdf(k) and .sf(k - 1) (the survival function,
), computed in a numerically careful way for large n. The comparison runs only when
SciPy is installed.
References
- Think Stats (3rd edition) — Allen B. Downey (
S010) - OpenIntro Statistics — OpenIntro (
S011)