Median
When you want a “typical” value from a list of numbers, the obvious choice is often the average. But averages can get pulled around by a few extreme values. The median is a simple alternative that stays calm even when the data has outliers.
What the median is
The median is the middle value after you sort the data from smallest to largest.
- If there’s an odd number of observations, the median is the single middle number.
- If there’s an even number, the median is the average of the two middle numbers.
Example: house prices (in $k) = 210, 220, 230, 240, 900. Sorted already, the middle value is 230, so the median is 230. The 900k “mansion” doesn’t change which value sits in the middle.
Why it’s different from the mean
The key feature is robustness: the median is much less sensitive to extreme values than the mean. If one exam score is recorded incorrectly as 0 or 1000, the mean can swing a lot, while the median often stays close to the real “typical” score.
Where it shows up in AI/ML
In machine learning workflows, the median is commonly used for:
- Robust scaling: centering data using the median (often paired with the IQR) reduces the impact of outliers; this is the idea behind scikit-learn’s RobustScaler.
- Imputation: filling missing values with the median is often safer than using the mean for skewed features (like income, transaction amounts, or time-on-site).
- Baseline predictions: for regression with absolute error (L1 loss), the median is the value that minimizes total absolute deviation, making it a natural “best constant” predictor.
Median is the middle value of a dataset when observations are sorted; if there are an even number of values, it is the average of the two middle ones. It is a robust measure of central tendency because it is less affected by outliers and skew than the mean, making it useful for summarizing features and targets in ML pipelines. Example: for [1, 2, 100], the median is 2.
Imagine lining up a group of people by height and picking the person standing right in the middle. That “middle” person represents a typical height without being thrown off by one extremely tall or short person.
In statistics, the median is the middle value when you sort a list of numbers from smallest to largest. If there are two middle numbers (because the list length is even), the median is the average of those two. In AI and machine learning, the median is useful because it gives a “typical” value that isn’t easily distorted by outliers, like a few unusually large prices or sensor errors.