Binomial in Practice
Scipy.stats.
A basketball player makes seventy percent of free throws. In a game, they take ten. What's the chance they make exactly seven? And what's the chance they make at least eight?

- 70% free throws
- Ten shots
- Exactly 7? At least 8?
pmf, cdf, and sf
PMF gives the chance of exactly one count. CDF, the cumulative distribution function, gives the chance of that count or fewer. And SF gives the chance of more than a count. Run it. Exactly seven has about a twenty seven percent chance. At least eight is about thirty eight percent.
from scipy.stats import binom
n, p = 10, 0.7
print("exactly 7: ", round(binom.pmf(7, n, p), 4))
print("7 or fewer:", round(binom.cdf(7, n, p), 4))
print("at least 8:", round(binom.sf(7, n, p), 4))
print("mean:", binom.mean(n, p))exactly 7: 0.2668 7 or fewer: 0.6172 at least 8: 0.3828 mean: 7.0
Binomials in ML
Accuracy on a test set is a binomial count. If a model is right on eighty five of a hundred test images, the true accuracy could easily be a bit higher, or lower. The binomial distribution tells you how much your score could wobble just by chance. That's why small test sets can be misleading.
| key | value |
|---|---|
| pmf | exactly k |
| cdf | k or fewer |
| sf | more than k |
| Test accuracy | a binomial count |
Summary
Use PMF for exactly, CDF for at most, and SF for more than. Next, the Poisson distribution, for counting events in time.
Key takeaways- binom.pmf / cdf / sf
- n and p
- Accuracy is binomial