The one idea: Outliers are the preprocessing problem you can see — a value sitting far from the rest, visible in a boxplot or a describe() call. Data leakage is the preprocessing problem you can't see: information from outside the training data (often the answer itself, in disguise) sneaks into the model, and the only symptom is a validation score that looks too good. Outliers cost you accuracy. Leakage costs you trust in every number your model has ever reported.
⚠️ The trap: A model that scores 98% AUC in validation and falls apart in production wasn't unlucky — it was almost certainly leaking. The single most common cause: fitting a scaler, imputer, or feature-selection step on the entire dataset before splitting into train and test, so the "test" set quietly influenced the "training" process. The score looks great right up until the model meets a transaction it couldn't have peeked at in advance — which, in production, is every transaction.
Outliers: the visible problem
An outlier is a data point that sits unusually far from the rest of the distribution — a $250,000 salary in a dataset otherwise full of $40–60k salaries, a sensor reading three times any other reading, a single 400-year-old "customer." Two common ways to flag them:
IQR method
import pandas as pd
import numpy as np
salaries = pd.Series([42000, 45000, 47000, 48000, 50000, 51000, 53000, 55000, 58000, 250000])
Q1 = salaries.quantile(0.25)
Q3 = salaries.quantile(0.75)
IQR = Q3 - Q1
lower_bound = Q1 - 1.5 * IQR
upper_bound = Q3 + 1.5 * IQR
print(f"Q1={Q1}, Q3={Q3}, IQR={IQR}")
print(f"Bounds: [{lower_bound}, {upper_bound}]")
print("Outliers:\n", salaries[(salaries < lower_bound) | (salaries > upper_bound)])
Q1=47250.0,…Keep reading: Handling Outliers and Data Leakage
Sign up free to read the full lesson, ask the AI tutor, and take practice questions.
- Full lesson content
- AI tutor for this section
- Practice questions