Modified Z-Score Using Median
What you'll learn: How to make Z-score anomaly detection more robust by swapping the mean and standard deviation with median-based measures.
The Problem with Traditional Z-Scores
Remember the standard Z-score method? It relies on the mean and standard deviation. Here's the catch: both are extremely sensitive to outliers. If your dataset already contains extreme values, they'll inflate the standard deviation and skew the mean—making it harder to detect those very outliers you're hunting for!
It's like using a broken ruler to measure itself—the tool is compromised by the problem.
Enter the Modified Z-Score
The modified Z-score replaces:
- Mean → Median (the middle value, unaffected by extremes)
- Standard deviation → Median Absolute Deviation (MAD) (a robust measure of spread)
How MAD Works
The Median Absolute Deviation measures how far data points typically are from the median:
- Calculate the median of your dataset
- Find the absolute difference between each point and the median
- Take the median of those differences
- Scale by a constant (≈1.4826) to make it comparable to standard deviation for normal distributions
The Modified Z-Score Formula
Modified Z-score = 0.6745 × (x - median) / MAD
The constant 0.6745 ensures consistency with traditional Z-scores under normal conditions.
When to Use It
Use modified Z-scores when:
- Your data might already contain outliers
- You're working with skewed distributions
- You need robust detection that won't be "fooled" by extreme values
The standard threshold is typically 3.5 (instead of 3 for traditional Z-scores).
Key Takeaway: Modified Z-scores use the median and MAD instead of mean and standard deviation, making anomaly detection robust even when outliers are already present in your data.