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

The Mode

The most common.

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

The third average is the mode. It's simply the most common value. It's the only average that works for categories, like the most popular colour, or the most common shoe size.

The Mode
From the video: The Mode
  • The most common value
  • Works for categories
  • Popular colour, common size

Counting to find the mode

A shop sold these shoe sizes today. Counter from the collections module counts each value, and most common gives the winner. Run it. Size eight sold three times, so eight is the mode. It also works on words, like colours.

mode.pypython
from collections import Counter

sizes = [7, 8, 8, 9, 8, 10, 7]
print(Counter(sizes).most_common(1))

colours = ["red", "blue", "red", "green", "blue", "red"]
print(Counter(colours).most_common(1))
Output
[(8, 3)]
[('red', 3)]

Three averages

Here's a summary. The mean is best for symmetric numbers, without extreme values. The median is best when there are outliers, or a long tail, like incomes or house prices. And the mode is for categories, or for the most common value. Reporting more than one often tells a richer story.

AverageHowBest for
Meansum ÷ countsymmetric data
Medianmiddle valueoutliers, skewed data
Modemost commoncategories

Summary

The mode is the most common value, and it works for categories too. Next, a closer look at when the mean and the median disagree.

Key takeaways
  • Counter(...).most_common
  • Works for words
  • Three averages
Next up: Mean or Median? — outliers pull the mean