All problems
Robust Scaling
Problem
Scale values robustly: (x_i - median) / IQR, where IQR = Q3 - Q1. Q1 is the median of the lower half of the sorted values and Q3 is the median of the upper half; for an odd count, exclude the median element itself from both halves.
If the IQR is 0, return a list of zeros. Empty input returns [].
Hint
Median-center, then divide by the interquartile range.
Test cases
case 1
in: [[1,2,3,4,5,6,7,8]]
expected: [-0.875,-0.625,-0.375,-0.125,0.125,0.375,0.625,0.875]
case 2
in: [[1,2,3,4,5]]
expected: [-0.6666666666666666,-0.3333333333333333,0,0.3333333333333333,0.6666666666666666]
case 3
in: [[7,7,7]]
expected: [0,0,0]
case 4
in: [[1,2,3,4]]
expected: [-0.75,-0.25,0.25,0.75]
Starter codePython
def robust_scale(values):
# Your code here
pass4 test cases · run your code against them in the editor