Outlier Detection: How to Find Outliers in Your Data and Decide What to Do
To find outliers in data, start with robust univariate rules: flag values beyond the IQR fences (1.5 times the interquartile range outside the quartiles) and rows whose modified z-score exceeds 3.5, then use a multivariate method such as isolation forest when unusual combinations matter. TensorTurn runs IQR and modified z-score outlier analysis automatically on upload and ranks the most anomalous rows, so you see exactly which records are suspect before deciding whether to remove, cap or keep them.
What counts as an outlier
An outlier is an observation that sits far from the bulk of the data. That definition hides two very different things. Some outliers are errors: a typo that turns 45 into 450, a sensor that reports -9999 when it fails, a currency column mixing dollars and cents. Others are rare but real: a genuine enterprise customer among small accounts, a fraudulent transaction, a machine about to fail. Errors should be fixed or removed. Rare real cases are often the most important rows in the dataset. Detection methods only find unusual values; deciding which kind they are is a judgment call.
Outlier detection methods compared
| Method | How it works | Best for | Weakness |
|---|---|---|---|
| IQR fences | Flags values below Q1 - k x IQR or above Q3 + k x IQR, with k = 1.5 (mild) or 3 (extreme) | Quick, robust univariate screening of any numeric column | Flags many points in naturally skewed data; one column at a time |
| Z-score | Flags values more than about 3 standard deviations from the mean | Roughly normal data with few outliers | Outliers inflate the mean and standard deviation, which can hide them (masking) |
| Modified z-score | Uses the median and median absolute deviation (MAD); flags |M| > 3.5 | Robust univariate detection even when outliers are present | Still one column at a time; MAD can be 0 for very repetitive columns |
| Isolation forest | Random trees isolate points; anomalies need fewer splits | Multivariate anomalies in larger tabular datasets | Needs a contamination guess; less interpretable; requires training |
The robust formulas in plain words
The interquartile range is the distance between the 25th percentile (Q1) and the 75th percentile (Q3), the span of the middle half of the data. The IQR rule draws a fence 1.5 IQRs below Q1 and 1.5 IQRs above Q3; anything outside is a mild outlier, and anything beyond 3 IQRs is an extreme one. Because quartiles barely move when a few wild values appear, the fences stay sensible even in dirty data.
The modified z-score, proposed by Iglewicz and Hoaglin, replaces the mean with the median and the standard deviation with the median absolute deviation: M = 0.6745 x (value - median) / MAD. Values with an absolute M above 3.5 are flagged. The classic z-score uses the mean and standard deviation, which the outliers themselves pull around, so a dataset with several large errors can end up with none of them crossing |z| > 3. The modified version avoids that masking effect.
Univariate vs multivariate outliers
Some records are only strange in combination. A height of 150 cm is normal and a weight of 95 kg is normal, but a 4-year-old with both is not. Univariate rules will never catch that row. Multivariate methods such as isolation forest, local outlier factor or a distance measure in a scaled feature space look at all columns together. A good workflow is to clean obvious univariate errors first, because they distort multivariate methods, and then run a multivariate pass if unusual combinations matter for your problem. If finding anomalies is the goal itself, such as fraud or defect detection, treat it as a modeling task rather than a cleaning step.
When to remove outliers and when to keep them
- Remove or correct values that are impossible: negative ages, dates in the future, sensor error codes, unit mix-ups. Fixing the unit is better than deleting the row when you can.
- Keep rare but real values when the model must handle them in production. A pricing model that never saw a large order will predict badly on the next one.
- Keep them when they are the target. In fraud, churn or failure prediction, removing outliers can remove the positive class.
- Consider capping (winsorizing) or a log transform for heavy-tailed features feeding linear models, instead of deleting rows.
- Prefer robust models and losses, such as tree-based models or Huber loss, when you cannot tell errors from extremes.
- Never drop outliers in the target column of a regression problem just to improve the metric; you are deleting the hard cases, not solving them.
Common mistakes
- Using the z-score on skewed data such as incomes or transaction amounts, where it flags the whole right tail.
- Removing outliers from the full dataset before the train/test split, so the test set no longer reflects real-world data.
- Applying one global rule to every column without looking at the histogram first.
- Deleting rows without recording why, which makes the result impossible to reproduce or explain.
How to detect outliers on TensorTurn
- Upload your dataset. Outlier analysis runs in your browser on upload alongside the rest of the profile.
- Review per-column IQR fences with mild (1.5x) and extreme (3x) counts to see which columns are affected.
- Open the ranked list of the most anomalous rows by modified z-score (|M| > 3.5) to inspect the actual records.
- Decide per case. In the AI data editor, ask in plain English to remove outlier rows, filter specific bad values, or fix a unit, and approve the planned steps.
- For multivariate anomaly detection as a model, describe it in chat, for example 'train an isolation forest on these columns', and TensorTurn generates and runs the scikit-learn notebook.
Frequently asked questions
What is the best way to find outliers in data?
For a single numeric column, the IQR rule and the modified z-score are the most robust starting points because they rely on quartiles and medians that outliers barely affect. For unusual combinations across several columns, use a multivariate method such as isolation forest.
What is the 1.5 IQR rule?
It flags any value more than 1.5 times the interquartile range below the first quartile or above the third quartile. Values beyond 3 times the IQR are usually called extreme outliers.
Is z-score or IQR better for outlier detection?
IQR is usually safer because it does not assume normality and is not distorted by the outliers themselves. The plain z-score works on roughly normal data, and the modified z-score based on the median is a robust alternative to both.
Should I remove outliers before training a model?
Remove or fix values that are clearly errors, but keep rare real cases the model will face in production, especially when they are the thing you want to predict. Capping or transforming heavy tails is often better than deleting rows.
Can TensorTurn show me which rows are outliers?
Yes. Alongside per-column IQR fences, TensorTurn ranks the most anomalous rows by modified z-score so you can inspect the specific records, then remove or fix them in the AI data editor.