Velamuvi AIAcademy
Probability

Lesson 14 of 16 · Distributions

The Normal Distribution

The normal distribution: the bell curve and its parameters, the 68-95-99.7 rule, z-scores, percentiles with NormalDist and the central limit theorem.

  • 7 min read
  • Intermediate
  • Reviewed
In this lesson you will learn
  • Describe the normal distribution and its parameters μ and σ
  • Use the 68-95-99.7 rule for quick estimates
  • Calculate z-scores, probabilities and percentiles with statistics.NormalDist
  • Explain the central limit theorem and why it makes the normal distribution so common
  • Recognise data that is not normal

The bell curve

Heights, measurement errors, exam scores and the total of many dice all have a similar shape: most values bunch around the middle, and fewer and fewer appear further out on either side. That shape is the normal distribution, also called the Gaussian distribution or the bell curve.

Move the sliders: μ slides the curve left and right, and σ makes it wider and flatter or narrower and taller. The area underneath always stays 1.

-8-6-4-20246800.20.40.60.8
normal density
The normal density. The peak is at μ, and about two-thirds of the area lies within one σ of it.

The 68-95-99.7 rule

For every normal distribution, whatever its μ and σ:

  • About 68% of values lie within 1 standard deviation of the mean.
  • About 95% lie within 2 standard deviations.
  • About 99.7% lie within 3 standard deviations.

Check it on the standard normal, the normal distribution with μ = 0 and σ = 1. Set the range to −1 to 1, then −2 to 2, then −3 to 3:

-4-202400.10.20.30.40.5
standard normal
area = 0.683
The area between −1 and 1 is about 0.683; between −2 and 2 about 0.954; between −3 and 3 about 0.997.

z-scores and NormalDist

To compare a value with its distribution, measure how many standard deviations it is from the mean.

Python's standard library has a normal distribution built in, statistics.NormalDist, with methods for the CDF, z-scores and percentiles (the inverse CDF):

Try it yourselfPython
from statistics import NormalDist

heights = NormalDist(mu=170, sigma=8)      # a simple model of adult heights, in cm

print(f"P(height <= 180)        = {heights.cdf(180):.3f}")
print(f"P(160 <= height <= 180) = {heights.cdf(180) - heights.cdf(160):.3f}")
print(f"z-score of 186 cm       = {heights.zscore(186):.1f}")
print(f"95th percentile         = {heights.inv_cdf(0.95):.1f} cm")

standard = NormalDist()                    # the standard normal: mean 0, sd 1
for k in (1, 2, 3):
    print(f"within {k} sd of the mean: {standard.cdf(k) - standard.cdf(-k):.4f}")

The last three lines are the 68-95-99.7 rule, calculated exactly.

The central limit theorem

Why is the normal distribution everywhere? Because of one of the most important results in all of probability:

A single die is flat, not bell-shaped at all. But add up 10 dice, 20,000 times:

Try it yourselfPython
import random
from collections import Counter
from statistics import fmean, pstdev

random.seed(14)
sums = [sum(random.randint(1, 6) for _ in range(10)) for _ in range(20_000)]   # 20,000 totals of 10 dice
print(f"mean = {fmean(sums):.2f} (theory: 35)   sd = {pstdev(sums):.2f} (theory: {(10 * 35 / 12) ** 0.5:.2f})")

counts = Counter(sums)
for low in range(16, 54, 3):                 # groups of three totals, centred on 35
    n = counts[low] + counts[low + 1] + counts[low + 2]
    print(f"{low}-{low + 2}  {'#' * (n // 80)}")

A bell appears, centred on 10 × 3.5 = 35, with standard deviation √10 × 1.708 ≈ 5.40, exactly as lessons 11 and 12 predict. The same thing happened to the binomial in lesson 13: it's a sum of Bernoulli trials, so for large n it looks normal too. Heights, measurement errors and test scores are each shaped by many small independent effects, which is why they come out roughly normal.

Common mistakes

Practice exercise

Exam scores follow a normal distribution with mean 65 and standard deviation 10. Find the share of students scoring 80 or more, and the score needed to be in the top 10%.

Your solutionPython
from statistics import NormalDist

scores = NormalDist(mu=65, sigma=10)     # exam scores: mean 65, standard deviation 10

# 1. What share of students score 80 or more?  (rounded to 4 decimals)
# 2. What score do you need to be in the top 10%?  (rounded to 1 decimal)
# Print both on one line.
Knowledge check

Test scores are normal with mean 500 and standard deviation 100. About what share of students score between 300 and 700?

Summary

  • The normal distribution N(μ, σ²) is a symmetric bell curve: μ sets the centre and σ the width.
  • 68-95-99.7 rule: about 68%, 95% and 99.7% of values lie within 1, 2 and 3 standard deviations of the mean.
  • A z-score z = (x − μ)/σ says how many standard deviations a value is from the mean.
  • statistics.NormalDist gives the CDF, z-scores and percentiles (inv_cdf).
  • The central limit theorem: sums and averages of many independent values are approximately normal.

Next: other useful distributions.

Finished reading? Tick it off to track your progress.