🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to Machine Learning Notes
Topic #65

Robust Scaling

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

\[ x' = \frac{x - \text{median}}{IQR}, \qquad IQR = Q3 - Q1 \]

Numerical Example

For a feature with median \(=60\), \(Q1=50\), \(Q3=80\) (so \(IQR=30\)), and \(x=70\):

\[ x' = \frac{70 - 60}{30} = 0.333 \]
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 StandardScaler out of habit on a dataset you already know has significant outliers, instead of reaching for RobustScaler.

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\).

Want to go beyond the notes?

Join CodingNow 2.0's Machine Learning course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Robust Scaling – FAQs

Quick answers about learning Robust Scaling in Machine Learning.

This free note from CodingNow 2.0 explains Robust Scaling in Machine Learning — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Machine Learning topic on CodingNow 2.0, including Robust Scaling, is 100% free with no signup required.
With focused practice, most students grasp Robust Scaling in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now