Definition
These are the three measures of central tendency, meaning a typical value of a dataset. The mean is the sum divided by the count. The median is the middle value after sorting. The mode is the most frequent value.
In simple words
Five friends earn 20, 25, 30, 35 and 40 thousand rupees. The mean and median are both 30. Then a crorepati joins. The mean jumps massively, and now describes nobody in the group, while the median barely moves. That's why salary reports usually quote the median.
Why it matters
It's usually the first thing you check on new data. Filling in missing values needs a choice between mean, median and mode. A large gap between mean and median warns you about outliers or skew before they damage a model.
How it works
| Measure | Affected by outliers? | Use it for |
|---|---|---|
| Mean | Yes, strongly | Symmetric numeric data, such as heights |
| Median | Barely | Skewed data, such as income and prices |
| Mode | No | Categories, such as the most common city |
Finding the median
- Sort the values.
- With an odd count, take the middle one.
- With an even count, average the two middle ones.
The maths
- The mean, read "x bar"
- How many values
- The weight of value i, such as an exam's credit hours
Data: 2, 3, 3, 5, 7, 40.
Mean = (2+3+3+5+7+40) / 6 = 60/6 = 10 Median = (3+5) / 2 = 4 Mode = 3
The mean of 10 is higher than five of the six values, because of the outlier 40. The median of 4 describes this data better.
In code
import statistics as st
data = [2, 3, 3, 5, 7, 40]
print("Mean:", st.mean(data))
print("Median:", st.median(data))
print("Mode:", st.mode(data))
without_outlier = data[:-1]
print("Mean without 40:", st.mean(without_outlier))
print("Median without 40:", st.median(without_outlier))Output
Mean: 10 Median: 4.0 Mode: 3 Mean without 40: 4 Median without 40: 3
Common mistakes
- Reporting only the mean for skewed data. Check the median too.
- Forgetting to sort before finding the median.
- Taking the mean of categories coded as numbers. The average of city codes means nothing.
Check yourself
Summary
- Mean: the average. Median: the middle. Mode: the most common.
- Outliers pull the mean, but barely move the median.
- A big gap between mean and median signals skew.
Finished reading?