Before any model, describe your data.
Centre
- Mean: the sum divided by the count.
- Median: the middle value once sorted (the average of the two middle ones for an even count).
- Mode: the most common value.
Spread
- Range: largest − smallest.
- Variance and standard deviation: the typical squared distance from the mean, and its square root. For a sample, divide by n − 1 instead of n; it corrects a small underestimate.
import statistics as st
marks = [62, 70, 70, 75, 81, 88, 91]
print("mean", round(st.mean(marks), 2), " median", st.median(marks), " mode", st.mode(marks))
print("range", max(marks) - min(marks), " sample SD", round(st.stdev(marks), 2))
marks.append(10)
print("after one outlier: mean", round(st.mean(marks), 2), " median", st.median(marks))Outliers
One salary of 1,000,000 among nine of about 30,000 drags the mean far up, while the median barely moves. That is why news reports quote the median income.
Python's statistics module computes all of these: mean, median, mode, stdev (n − 1) and pstdev (n).
Quick check
Practice problems for this lesson
My notes
Write down what you want to remember from this lesson. Notes are saved on this device as you type, and appear on your dashboard.