Code N Curry MLCode & Curry ML
Back to Library
CURRICULUM: S2 · E3 · 12 min
VERIFIED BLUEPRINT

Mean, Median & the Lying Average

TIME: 12 min
🍽️YIELD: 1 outlier-proof summary of any dataset
📓CHAPTER: S2E3

The Idea

CONCEPT
A weighing scale with eight thalis stacked near 250g and one absurd banquet platter at 950g. The mean marker is dragged toward the platter; the median marker stays with the crowd. Margin note: 'the mean follows the money, the median follows the people.'

The mean minimises squared distance to all points, so a single far-away point exerts enormous pull — squared error punishes distance quadratically.

The median minimises absolute distance; an outlier counts as just one more vote, not a louder one.

Variance uses n−1 (Bessel's correction) on samples because the sample mean already 'used up' one degree of freedom.

Report mean ± std for symmetric data; switch to median + IQR the moment the histogram has a long tail (income, house prices, delivery times).

In the Test Kitchen below: add one banquet platter and watch the ±1 std bracket explode while the median holds.

⚗️ The Test Kitchen

INTERACTIVE LAB

Don't just read the recipe — taste it. Drag, click and break things below.

EXP 01

Weighing the Thalis

"one outlier can lie to your mean"

Each dot is a thali on the scale. Click the paper to add plates, click a plate to remove it. Then add one absurd 950g banquet platter: the mean (purple) chases the outlier, the median(teal) holds its ground, and the standard-deviation bracket blows wide open. Robustness is a choice.

0g250g500g750g1000g± 1 stdmeanmedian
mean 270g · median 270g · std 58g

FIG L.3: CENTRAL TENDENCY — THE MEAN FOLLOWS OUTLIERS, THE MEDIAN RESISTS (BESSEL n−1 STD)

The Recipe

CODE
REQUIRED SPICESmeanmedianvariancestdoutliers
Outlier vs the average
import numpy as np

plates = np.array([180, 220, 240, 260, 280, 300, 320, 360])
print(plates.mean(), np.median(plates))   # 270.0 270.0 — they agree

plates = np.append(plates, 950)           # one banquet platter
print(plates.mean())                      # 345.6 — mean got dragged
print(np.median(plates))                  # 280.0 — median barely moved
print(plates.std(ddof=1))                 # Bessel's n-1: sample std
NEXT EXPERIMENT
CODE & CURRY
APPROVED
ML KITCHEN