Data Quality › Outliers

Michael BrenndoerferMay 31, 20258 min read
Machine Learning from ScratchAll chapters
Part 1 of 9Statistics 101
Chapter 9Data Quality › Outliers
Reading section 5 of 9 · Outliers · 8 minSection 5 of 9 · 8 min

Book contents

Section 5 of 9 · 8 min read

Data Quality › OutliersOne section · Sections in this chapter5 / 9 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Outliers are observations that deviate markedly from the overall pattern in the data. They command special attention because they can exert disproportionate influence on statistical summaries, regression estimates, and model predictions. The appropriate response to outliers requires careful judgment balancing legitimate extreme values against erroneous measurements.

Types of Outliers

Outliers arise from different sources that warrant different responses. Data entry errors represent one common source: a recorded age of 250 or an income of $10 billion for a salaried employee clearly indicate mistakes that should be corrected or removed. These erroneous outliers provide no information about the population of interest and only distort analysis if retained.

Measurement errors produce outliers when instruments malfunction or reading errors occur. A temperature sensor reporting 500°F in an indoor environment or a laboratory result far outside physiologically possible ranges indicate measurement problems. Like data entry errors, these measurement outliers should be excluded or corrected when detected.

Natural variation generates legitimate outliers representing actual extreme values in the population. Some individuals truly are seven feet tall, some transactions truly involve millions of dollars, and some rare events truly occur despite low probability. These natural outliers are valid observations that reflect real phenomena, and removing them discards information about distributional tails that may be precisely what we want to understand.

Population heterogeneity produces outliers when a dataset inadvertently combines distinct subpopulations. A dataset containing both children and adults will show outliers when analyzing variables like height or income if the analysis treats all observations as coming from a single population. These outliers indicate misspecification rather than data quality problems. The solution is to model the populations separately or include covariates distinguishing them.

Detection Methods

Multiple statistical and visual approaches help identify potential outliers. Visual inspection through box plots, scatter plots, and histograms gives intuitive identification of unusual values in univariate and bivariate contexts. Box plots flag observations beyond 1.5 times the interquartile range from the quartiles.

The z-score method identifies outliers based on how many standard deviations an observation falls from the mean. Values with |z| > 3 are commonly flagged, corresponding to observations more than three standard deviations from the mean. This approach assumes normality and can be misleading for skewed distributions where extreme values are expected. The median absolute deviation provides an alternative to standard deviation that is less influenced by the outliers being detected.

In regression contexts, outliers manifest in different ways requiring different diagnostics. Leverage measures how unusual an observation is in terms of predictor variable values, identifying points with potential to influence the fitted model. Influence measures like Cook's distance quantify how much regression estimates change when an observation is excluded, directly assessing impact on results. Residual plots reveal outliers in the response variable conditional on predictors.

The following visualizations demonstrate different approaches to identifying outliers, showing how box plots and regression influence diagnostics capture different aspects of unusual observations.

Out[6]:
Visualization
Box plot showing outlier detection with IQR method.
Box plot outlier detection using the IQR method. Points beyond 1.5 times the interquartile range from the quartiles (shown as whiskers) are marked as outliers (orange). This distribution-free method identifies extreme values in the univariate distribution. The box shows the 25th to 75th percentiles, the line shows the median, and the whiskers extend to the most extreme non-outlier values.
Regression plot showing different types of outliers with leverage and influence.
Regression outliers showing different types: high leverage (unusual X values), high residuals (unusual Y values given X), and high influence (strong impact on fitted line). The outlier in the upper right has high leverage and influence, pulling the regression line (red dashed) away from the true relationship (blue solid). Points are sized by Cook''s distance, a measure of influence.

Handling Outliers

The appropriate response to identified outliers depends on their suspected origin and the analysis goals. Investigation should precede action: examine outliers carefully to assess whether they represent errors, measurement problems, or legitimate extreme values. Check original data sources when possible to verify recorded values. Look for patterns in outliers that suggest systematic data quality issues.

For clearly erroneous outliers from data entry or measurement errors, correction or removal is appropriate and should be documented. Record the criteria used to identify errors and the number of observations affected. If the true value can be recovered from source documents, correction is preferable to deletion. Otherwise, treat erroneous values as missing data and apply appropriate missing data methods.

For legitimate extreme values representing natural variation, retention is generally appropriate as these observations provide information about the population. However, consider whether the extreme values warrant special attention in analysis. Reporting results both with and without outliers shows their influence and acknowledges uncertainty. Robust statistical methods that downweight outliers automatically, such as robust regression or trimmed means, provide alternatives to complete removal.

When outliers indicate population heterogeneity, stratified analysis or including appropriate covariates addresses the underlying issue. Analyzing subpopulations separately or modeling heterogeneity explicitly provides more appropriate inference than treating outliers as problems to be removed. This approach recognizes that "outliers" may represent a distinct but important segment of the population.

Transforming variables can reduce the influence of outliers without removing them. Logarithmic transformation compresses the right tail of positively skewed distributions, bringing extreme values closer to the bulk of the data. This approach works well for variables like income or reaction times where extreme values are legitimate but would otherwise dominate analyses. However, transformations change the scale of interpretation and may not be suitable for all purposes.

The following visualization shows how a single extreme outlier dramatically affects the mean while leaving the median relatively unchanged, illustrating the importance of robust statistics for skewed or outlier-prone data.

Out[7]:
Visualization
Histogram showing impact of outlier on mean vs median.
Impact of an extreme outlier on mean versus median. The bulk of the data (blue histogram) is centered around 50. Adding one extreme outlier at 200 (orange point) shifts the mean from 49.2 to 50.7, while the median remains near 49.1. This demonstrates why the median is more resistant to extreme observations than the mean.