Robust scaling rescales a feature using the median and interquartile range (IQR) instead of the mean and standard deviation — making it resistant to the exact outliers that break standardization and normalization.
Formula
Numerical Example
For a feature with median \(=60\), \(Q1=50\), \(Q3=80\) (so \(IQR=30\)), and \(x=70\):
from sklearn.preprocessing import RobustScaler
import numpy as np
# includes one extreme outlier (500) that would distort mean/std heavily
X_train = np.array([[45], [50], [55], [60], [65], [70], [500]])
scaler = RobustScaler()
X_train_scaled = scaler.fit_transform(X_train)
print(X_train_scaled.ravel())
# The outlier (500) still scales to a large value, but the OTHER points stay
# well-spread and usable — unlike MinMaxScaler, which would crush them all near 0
Why the Median/IQR Combination Resists Outliers
The mean shifts noticeably when a single extreme value is added; the median barely moves, since it only cares about the middle-ranked value. Likewise, standard deviation grows sharply with one huge outlier; IQR (based only on the 25th/75th percentiles) is unaffected by values beyond those percentiles. This is exactly why mean vs median intuition carries over directly to scaler choice.
Practical Use Cases
- Financial data (income, transaction amounts) which is naturally skewed and outlier-prone
- Sensor data with occasional extreme faulty readings you don't want to discard outright
Advantages
- Outliers don't distort the scale for the rest of the (normal) data points
- No need to remove outliers before scaling — robust scaling handles their influence automatically
Limitations
- Doesn't produce a fixed, bounded range like Min-Max scaling
- The outlier itself is still present in the data — robust scaling controls its influence on scaling, not its presence; you may still want outlier treatment separately.
Common Mistakes
- Defaulting to
StandardScalerout of habit on a dataset you already know has significant outliers, instead of reaching forRobustScaler.
Interview Relevance
Q: "Your dataset has a few extreme outliers you want to keep. Which scaler do you use?" RobustScaler — it uses median and IQR, which aren't pulled around by extreme values the way mean and standard deviation (StandardScaler) or min/max (MinMaxScaler) are.
Practice Question
A feature has median \(=40\), \(Q1=30\), \(Q3=55\). Compute the robust-scaled value for \(x=85\).