AI Hints
Home›Statistics & Math for ML Tutorial›Common Distributions
Statistics & Math for ML · Lesson 40 of 138

Binomial in Practice

Scipy.stats.

⏱ 2 min read▶ Video at 45:37🎓 Free
Watch this lesson in the Statistics & Math for ML courseWatch on YouTube ↗Full Statistics & Math for ML course

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?

Binomial in Practice
From the video: Binomial in Practice
  • 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.

free_throws.pypython
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))
Output
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.

keyvalue
pmfexactly k
cdfk or fewer
sfmore than k
Test accuracya 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
Next up: The Poisson Distribution — counting events