AI Hints
Statistics & Math for ML · Lesson 39 of 138

The Binomial Distribution

Counting successes.

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

Flip a coin ten times. How many heads will you get? Probably around five, but it could be anything from zero to ten. The binomial distribution gives the chance of each count.

The Binomial Distribution
From the video: The Binomial Distribution
  • Ten flips
  • How many heads?
  • The binomial distribution

Its two settings

A binomial distribution describes the number of successes in N independent tries, where each try succeeds with the same probability P. Ten coin flips is N equals ten, and P equals a half. Ten free throws by a seventy percent shooter is N equals ten, and P equals zero point seven.

keyvalue
nnumber of tries
pchance of success each time
Counts0, 1, … n successes
Meann × p

Drawing it

Sci Pi's binom gives us the probability of each count, with PMF, the probability mass function. We draw it as bars. Run it. Five heads is the most likely, but four and six are close behind. Zero or ten heads is very rare.

binom.pypython
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import binom

k = np.arange(0, 11)
plt.bar(k, binom.pmf(k, n=10, p=0.5))
plt.title("Heads in 10 flips")
plt.xlabel("number of heads"); plt.xticks(k)
plt.savefig("binom.png")

Summary

The binomial distribution counts successes in N tries with chance P. Its mean is N times P. Next, using it to answer real questions.

Key takeaways
  • n tries, chance p
  • binom.pmf
  • Mean = n × p
Next up: Binomial in Practice — scipy.stats