Outliers: find them and decide what to do
The register at "Mama John's" sees ordinary receipts — and suddenly an order for twenty pizzas: an office party. One such value can flip the mean, inflate the variance and ruin a model. Yet an outlier is not always "an error": sometimes it is the most valuable thing in the data. On the right — the same data in three ways (points, histogram, box plot); we'll go step by step through how to spot an outlier and how to deliberately choose what to do with it.
One outlier drags everything: the mean is ≈ 47, the histogram stretches into a long tail, a dot appears past the whisker on the box plot. The median and the Q1–Q3 box barely move — they are robust. First understand the outlier's nature (error or reality), then pick the action — and document it.
An outlier is a value that has broken far away from the bulk. The widget shows the same data in three ways at once: points at the bottom (the green mean has drifted toward the outlier, the yellow median stayed with the group); a histogram in the middle (the outlier is a lonely bar far to the right — a long tail); a box plot on top (a red dot flying past the whisker). One extreme moves the mean, but barely touches the median and the box.
A decision about an outlier is a decision about its nature: a data error — fix it; a real "big customer" — keep it and change the method, not the data.
Before any analysis, an analyst draws a box plot and a histogram and checks the outliers: a lonely bar in the tail and a dot past the whisker are visible at once. Then separates: input errors get fixed, real extremes get handled deliberately (robust measures, capping, log), and the decision is documented so the analysis stays reproducible.
Sometimes the outlier IS the goal: a fraudulent transaction, a failing server, anomalous demand. Then you do not remove it — you hunt for it; a whole field of anomaly detection is built on this.
In money and response times outliers are a fact of life, not a rarity: there is always a pair of giant orders or hung requests. That is why medians and percentiles are the default there, and spread is read off the box plot.
In machine learning uncleaned erroneous outliers drag the model toward themselves (especially with squared error), while real ones are, on the contrary, informative; confusing the two is expensive.
Definitions
The 1.5·IQR rule and the |z|>3 threshold (z is the distance from the mean in standard deviations — more on this in the normal distribution lesson) are heuristics, not truth: different distributions have different "normal" shares of outliers. On heavily skewed data 1.5·IQR will flag many perfectly normal tail values.
Removing outliers changes conclusions and easily turns into result-fitting. Every removal must be justified by the nature of the data and documented.