Skip to content
Tutorials Center
My learning

Topics

Lesson 10 of 37 ยท Averages and Spread

Mean, Median and Mode

Learn to calculate the mean, median and mode, decide which average fits your data, and see how an outlier changes each one, with Python to check your work.

An average is a single number that represents the "typical" value of a data set. There are three common ones, called measures of central tendency: the mean, the median and the mode. Each answers a slightly different question, and choosing the wrong one can give a misleading picture.

The mean

The mean is the "fair share" average: add up all the values and divide by how many there are.

mean = (sum of all values) / (number of values)

Data: 3, 5, 5, 7, 9, 11. The sum is 40 and there are 6 values, so the mean is 40 / 6 โ‰ˆ 6.67.

The mean uses every value, which is its strength and its weakness. One extreme value pulls it strongly.

The median

The median is the middle value when the data are sorted from smallest to largest.

  • With an odd number of values, it is the middle one.
  • With an even number, it is the mean of the two middle values.

Data: 3, 5, 5, 7, 9, 11 is already sorted. There are 6 values, so the middle two are 5 and 7, and the median is (5 + 7) / 2 = 6.

For 7 values, the median is the 4th. In general, for n values the median sits at position (n + 1) / 2.

The mode

The mode is the most frequent value. A data set can have one mode, several modes (bimodal, multimodal) or none if every value appears once. The mode is the only average you can use for categorical data (the most popular color, for example).

In 3, 5, 5, 7, 9, 11, the mode is 5.

Python Three averages from scratch

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Outliers and robustness

An outlier is a value far from the rest. Suppose five friends have the following savings in dollars: 20, 25, 30, 35, 40. The mean is 30 and the median is 30. Now a sixth friend with 500 joins.

Python What one extreme value does

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The mean jumps a lot, while the median barely moves. We say the median is robust (resistant to outliers) and the mean is sensitive.

Which average should I use?

Average Best when Weakness
Mean Data are roughly symmetric, no extreme values; you need every value to count Pulled by outliers and skew
Median Data are skewed or have outliers (incomes, house prices) Ignores the size of the other values
Mode Categorical data, or you want the most common value (shoe size to stock) May not exist, may not be unique, ignores other values

News reports about "average income" often use the median, because a few very rich people would drag the mean far above what a typical person earns.

Mean, median and shape

In a symmetric distribution the mean and median are about equal. In a right-skewed distribution the long tail drags the mean above the median; in a left-skewed one it drags it below. Comparing them is a quick check for skew.

Working backward

Often a problem gives the mean and asks for a missing value. Since total = mean ร— n, you can find the missing value.

Example: five test scores have a mean of 14, and four of them are 10, 12, 15 and 17. The total must be 14 ร— 5 = 70. The four known scores add to 54, so the fifth score is 70 โˆ’ 54 = 16.

Python Find the missing value

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What is the median of 8, 3, 12, 5, 9?

    Sorted: 3, 5, 8, 9, 12. The middle value is 8. (7.4 is the mean.)
  2. 2. What is the mean of 4, 6, 6, 8, 11?

    The sum is 35, and 35 / 5 = 7.
  3. 3. Which average is least affected by one extremely large value?

    The median depends on position, not size, so one extreme value barely changes it.
  4. 4. A shop wants to know which shoe size sells most often. Which average?

    The most frequent size is the mode, and it must be an actual size, unlike a mean such as 38.4.
  5. 5. The mean of 4 numbers is 9. Three of them add to 28. What is the fourth?

    The total is 4 ร— 9 = 36, and 36 โˆ’ 28 = 8.

Summary

  • Mean = total รท count; median = middle of the sorted values; mode = most frequent value.
  • The mean uses all values but is sensitive to outliers; the median is robust; the mode works for categories.
  • In skewed data the mean is pulled toward the tail.
  • Use total = mean ร— n to find a missing value.

Next: Averages from Frequency Tables