Skip to content
DeepForgeby svx
All problems
MediumStatisticsst-033

Robust Z-Score via MAD

Problem

Return the robust z-score 0.6745 * (x - median) / MAD, where MAD is the unscaled median absolute deviation. Return 0.0 if data is empty or MAD is zero. The 0.6745 constant makes the score comparable to a standard z-score for normal data.

Hint

Compute the median and MAD, then scale.

Test cases

case 1
in: [[1,2,3,4,5],5]
expected: 1.349
case 2
in: [[1,2,3,4,5],1]
expected: -1.349
case 3
in: [[5,5,5],5]
expected: 0
case 4
in: [[1,2,3,4,5,6,7],7]
expected: 1.01175
case 5
in: [[],3]
expected: 0
Starter codePython
def robust_zscore(data, x):
    # Your code here
    pass

5 test cases · run your code against them in the editor