Handling Outliers: Removal, Capping, and Transformation
You'll learn three practical strategies for managing outliers once you've detected them in your data.
The Core Idea
After identifying outliers (using methods from lesson 436-437), you need to decide what to do with them. Simply detecting outliers isn't enough—you must handle them appropriately. The three main strategies are:
1. Removal (Trimming)
Delete rows containing outliers entirely. This works when outliers represent data errors or you have abundant data. However, removing too much data can hurt model performance.
Analogy: Like throwing out spoiled fruit from a basket—simple but wasteful if you discard too much.
2. Capping (Winsorization)
Replace extreme values with a threshold (usually the 5th and 95th percentiles, or 1st and 99th). Values beyond these limits are "capped" at the boundary.
Example: If income above 500K, a billionaire's income becomes $500K in your dataset.
This preserves the number of samples while limiting extreme influence.
3. Transformation
Apply mathematical functions to compress the scale and reduce outlier impact. Common transformations include:
- Log transformation:
log(x)reduces right-skewed data - Square root:
sqrt(x)for moderate skewness - Box-Cox transformation: automatically finds the best power transformation
Analogy: Like adjusting camera exposure to see both bright and dark areas—transformations bring outliers closer to the main distribution without discarding information.
Which Strategy to Choose?
- Use removal sparingly when outliers are clearly errors
- Use capping when you need to preserve all samples
- Use transformation when outliers are legitimate but need taming, especially before algorithms sensitive to scale
Key Takeaway: The three outlier-handling strategies—removal, capping, and transformation—each preserve different aspects of your data; choose based on whether outliers represent errors, legitimate extremes, or skewed distributions.