Mode — The Popular Vote
The mode tells you which value shows up the most — the crowd favourite of your data set.
The mode is the most frequently occurring value. Use SciPy's mode() to find it instantly.
EXERCISE
1What Is the Mode?
The mode is the simplest statistic of all — it is just the value that shows up the most often.
Think of the mode like the bestselling item at a store. You do not care about the average price or the middle price — you want to know which item people actually buy the most.
Finding the mode:
# By inspection: which value repeats most?
speed = [99, 86, 87, 88, 111, 86, 103, 87, 94, 78, 77, 85, 86]
# 86 appears 3 times — more than any other value
# Mode = 86
Using SciPy:
from scipy import stats
speed = [99, 86, 87, 88, 111, 86, 103, 87, 94, 78, 77, 85, 86]
x = stats.mode(speed)
print(x)
# Output: ModeResult(mode=86, count=3)
Using Counter (standard library):
from collections import Counter
speed = [99, 86, 87, 88, 111, 86, 103, 87, 94, 78, 77, 85, 86]
counts = Counter(speed)
print(counts.most_common(1))
# Output: [(86, 3)]
Pro Tip: The mode is the only measure of central tendency that works for ALL data types — numerical, categorical, and ordinal. You cannot calculate the "mean" of colours, but you can absolutely find the most popular colour.
EXERCISE
2Unimodal, Bimodal, and No Mode
Data can have one mode, multiple modes, or no mode at all — and each scenario tells you something different about your data.
Modes are like peaks on a mountain range. One peak means one mode (unimodal). Two peaks means two modes (bimodal). A flat plateau means no mode — every value appears equally often.
Unimodal — one clear winner:
from collections import Counter
data = [1, 2, 3, 3, 3, 4, 5]
print(Counter(data).most_common(2))
# Output: [(3, 3), (1, 1)]
# Mode = 3 (appears 3 times, everything else appears once)
Bimodal — two winners:
from collections import Counter
data = [1, 2, 2, 3, 4, 4, 5]
print(Counter(data).most_common(2))
# Output: [(2, 2), (4, 2)]
# Two modes: 2 and 4 (both appear twice)
No mode — everyone ties:
from collections import Counter
data = [1, 2, 3, 4, 5]
print(Counter(data).most_common())
# Output: [(1, 1), (2, 1), (3, 1), (4, 1), (5, 1)]
# No mode — every value appears exactly once
Pro Tip: Bimodal data is a red flag in ML — it often means your data set actually contains two different populations mixed together. If exam scores are bimodal (peaks at 40 and 85), you might be mixing students who studied with those who did not. Splitting them would give you better models.
EXERCISE
3Mode in the Real World — Categorical Data's Best Friend
The mode truly shines with categorical data — where mean and median are completely useless.
Asking "what is the average colour?" is like asking "what is the square root of a sandwich?" — it is a category error (pun intended). The mode is the only stat that makes sense here.
Mode with colours (categorical):
from collections import Counter
cars = ["red", "white", "black", "white", "gray",
"white", "blue", "red", "black", "white"]
counts = Counter(cars)
print(counts.most_common(3))
# Output: [('white', 4), ('red', 2), ('black', 2)]
# Mode = white (most popular colour)
Mode for yes/no data:
from collections import Counter
autopass = ["Y", "Y", "N", "Y", "Y", "N", "Y", "N", "N", "Y"]
counts = Counter(autopass)
print(counts.most_common())
# Output: [('Y', 6), ('N', 4)]
# Mode = Y (most cars pass automatically)
Mean vs Median vs Mode — the full picture:
| Measure | Best For | Ignores Outliers? | Works on Categories? |
|---|---|---|---|
| Mean | Symmetric numerical data | ❌ No | ❌ No |
| Median | Skewed numerical data | ✅ Yes | ❌ No |
| Mode | Any data type | ✅ Yes | ✅ Yes |
Pro Tip: In ML preprocessing, the mode is your go-to for filling in missing categorical values. If 60% of customers chose "email" as their contact preference, filling blanks with "email" is a much better guess than leaving them empty or making something up.
