Skip to content
tezvyn:

When should you keep outliers, not drop them?

Source: interviewMediumHow cards are made

Summary

judgment about when outliers are signal.

Key points

keep them in fraud or anomaly detection, use robust models and metrics.

Watch out for

blindly deleting anything beyond three standard deviations.

What's really being asked

The interviewer wants to know whether you treat outliers reflexively or contextually. Strong candidates distinguish data-entry errors from rare-but-real observations, and connect that distinction to model and metric choices.

The full answer

Keep outliers whenever they are the phenomenon of interest. In fraud detection, intrusion detection, equipment failure, or rare-disease diagnosis, the outliers ARE the positive class, so deleting them destroys the signal. Keep them when the underlying process is genuinely heavy-tailed, such as income, insurance claims, or web traffic, where extreme values are expected and informative. When you keep them, prefer models that tolerate them: tree-based ensembles like random forests and gradient boosting split on thresholds and are insensitive to magnitude, unlike ordinary least squares. Adjust evaluation too, using MAE or median absolute error rather than RMSE, which squares and overweights large errors.

The mistakes people make

Saying you always remove points beyond three standard deviations or 1.5 times the interquartile range. This conflates statistical extremeness with invalidity and can silently delete the exact records the business cares about.

What usually comes next

How do you distinguish a real outlier from a data error? How would winsorizing or a log transform compare to deletion? Would your answer change for a deep neural network versus a linear model?

A concrete example

A payments team builds a model to catch fraudulent transactions. A handful of accounts show charges fifty times their normal volume. Removing them as outliers would erase most of the fraud labels. Instead the analyst keeps them, trains a gradient-boosted classifier robust to scale, and evaluates with precision and recall on the rare positive class rather than overall accuracy, which would look high even if every fraud case were missed.

Interview question

A team is building an anomaly detector for equipment failures. Why is automatically dropping all points beyond three standard deviations a poor first step?

  • a.It always makes the training set too small to fit any model
  • b.It removes the rare failure events the model is supposed to detectCorrect
  • c.Standard deviation cannot be computed on sensor data
  • d.It guarantees the model will overfit the remaining data
Why?

In anomaly detection the extreme points are the target signal, so deleting them removes the positive class. The size argument is wrong because outliers are typically a small fraction of the data.

Just read this? Test yourself on what you have been reading.

Read the original → towardsdatascience.com

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.

See open roles