Lesson · ⏱ 7 min read

📊 Averages and spread: mean, median, variance

EnglishHinglish

🏠 Real-life example

Nine friends earn ₹30,000 a month and one earns ₹10 lakh. The 'average' (mean) salary comes out above ₹1.2 lakh, which describes nobody! The median, the middle person's salary, is ₹30,000 and tells the real story. And 'spread' asks whether everyone earns about the same or the numbers are all over the place.

💡 In simple words

Before modelling, you describe your data. The mean is the sum divided by the count, and it's pulled around by extreme values (outliers). The median is the middle value after sorting, and it's robust to outliers. The mode is the most common value. Spread measures how scattered the numbers are: variance is the average squared distance from the mean, and standard deviation is its square root, in the same units as the data. Always check both the centre and the spread.

🎬 See how it works

₹0k₹200k₹400k₹600k₹800k₹1000k₹1000kMedian ₹30kMean ₹127k

Nine salaries sit at ₹30k. When one ₹10 lakh salary arrives, the mean jumps to ₹127k but the median stays at ₹30k.

🪜 Step by step

  1. Mean: add all values and divide by how many. Good for symmetric data like heights.
  2. Median: sort the values and take the middle one. Use it when there are extreme values, like salaries or house prices.
  3. Spread: range (max minus min) is quick but sensitive. Standard deviation tells how far values typically are from the mean.
  4. Percentiles: the 90th percentile is the value 90% of data is below. Used for things like delivery time or API latency (p90, p99).
  5. Always plot a histogram: two datasets can have the same mean but very different shapes.

🔑 Key terms

Mean
The usual average: sum ÷ count.
Median
The middle value when sorted. Not fooled by outliers.
Standard deviation
The typical distance of values from the mean.

👀 See it in action

python
import statistics as st
salaries = [30, 30, 30, 30, 30, 30, 30, 30, 30, 1000]  # in ₹ thousand
print(st.mean(salaries))    # 127.0  ← misleading
print(st.median(salaries))  # 30.0   ← the real picture
print(round(st.stdev(salaries), 1))  # 306.7 ← huge spread

One outlier changes the mean a lot but barely moves the median.

⚠️ Common mistakes to avoid

  • Reporting only the average. 'Average delivery time is 2 days' hides that 10% of orders take a week.
  • Using the mean for skewed data like income. A few very high values pull it up; the median is more honest.

✅ Quick check

House prices in a city include a few very expensive villas. Which describes a typical house better?

  1. Mean
  2. Median
  3. Maximum
Show answer

B. Median: A few villas pull the mean up. The median stays at the middle house.

🙋 Questions learners ask

What's the difference between variance and standard deviation?

Standard deviation is the square root of variance. It's in the same units as your data (rupees, seconds), so it's easier to interpret.

Why do tech teams talk about p99 latency?

Because averages hide the slow cases users actually notice. p99 means 99% of requests are faster than this; the slowest 1% often matter most to unhappy users.

📌 Remember

Use the median when there are outliers, and always look at the spread too.

Learn this as part of a full course

Track your progress, take the quick checks and follow the lessons in the right order. This lesson is part of:

AI Foundations Path · ML Engineer

Continue in the course