Last updated

Mean, Median, and Mode

Definition: These three numbers describe the "centre" of your data. Understanding your data is the first step of any ML project.

  • Mean — the average (add all up, divide by how many)
  • Median — the middle value when sorted
  • Mode — the value that appears most often

Example — Python makes this easy

Python has a built-in statistics module, so no extra libraries are needed:

import statistics as st
ages = [21, 25, 25, 30, 32, 40]
print("Mean:  ", st.mean(ages))
print("Median:", st.median(ages))
print("Mode:  ", st.mode(ages))

Why each one matters

The mean can be pulled by extreme values (one billionaire raises the "average" wealth of a room). The median is more robust to outliers. The mode is useful for categories, like the most common product sold.

💡 Try it: change the numbers in ages and re-run to see how each measure responds.

Try it Yourself
Output

          
Ad · responsive