Outlier

Outlier Detection and Handling is the process of identifying and managing data points that deviate significantly from the rest of the dataset — using statistical methods (Z-score, IQR), distance-based approaches (Local Outlier Factor), or isolation-based algorithms (Isolation Forest) to find anomalies that can either corrupt model training (a $10M salary when the mean is $60K) or represent the most valuable signal in the data (fraudulent transactions, equipment failures, security breaches).

What Are Outliers?

  • Definition: Data points that are significantly different from the majority of observations — lying far from the center of the data distribution, potentially due to measurement errors, data entry mistakes, or genuine rare events.
  • The Dual Nature: Outliers are either errors to remove or the most important data to keep. A $10M salary in an income dataset is probably a data error. A $10M transaction in a banking dataset might be fraud — the whole point of the analysis.
  • Impact on Models: Linear regression is heavily influenced by outliers (a single extreme point can tilt the regression line). Tree-based models are more robust. KNN distance calculations are distorted by outliers.

Detection Methods

MethodApproachAssumptionFormula / Rule
Z-ScoreDistance from mean in standard deviationsData is roughly normalOutlier ifz> 3 ($z = \frac{x - \mu}{\sigma}$)
IQR (Interquartile Range)Distance from median quartilesNo distribution assumptionOutlier if x < Q1 - 1.5×IQR or x > Q3 + 1.5×IQR
Isolation ForestHow easily a point can be isolated by random splitsAnomalies are rare and differentFewer splits to isolate = more anomalous
Local Outlier Factor (LOF)Density compared to neighborsOutliers are in low-density regionsLOF score > 1 = lower density than neighbors
DBSCANPoints not assigned to any clusterOutliers are noisePoints with too few neighbors = outlier

IQR Method Example

StepCalculation
Sort data[20, 25, 28, 30, 32, 35, 38, 40, 150]
Q1 (25th percentile)26.5
Q3 (75th percentile)39
IQR = Q3 - Q112.5
Lower fence = Q1 - 1.5 × IQR7.75
Upper fence = Q3 + 1.5 × IQR57.75
Outlier: 150 > 57.75✓ Flagged

Handling Strategies

StrategyMethodWhen to Use
RemoveDelete outlier rowsMeasurement errors, data entry mistakes
Cap / WinsorizeReplace with 1st/99th percentile valuePreserve information while limiting impact
TransformLog transform to reduce skewRight-skewed distributions (income, prices)
Separate ModelTrain different models for normal vs outlier regimesWhen outliers follow different patterns
KeepLeave outliers in the datasetFraud detection, anomaly detection (outliers ARE the target)
Robust MethodsUse median instead of mean, MAD instead of stdWhen outliers can't be removed

Outlier Detection and Handling is the essential data quality step that protects model integrity — requiring practitioners to distinguish between errors to remove and valuable anomalies to keep, choose appropriate detection methods based on data distribution and dimensionality, and apply handling strategies that preserve the underlying signal while eliminating the noise that degrades model performance.

Take outlier further

Ask the copilot about this term, or have our engineers assess it against your process.