All problems
Huber Location One Step
Problem
Perform one step of Huber's M-estimator for location: start at the median, compute the scale 1.4826*MAD, form weights that are 1.0 within c*scale and c*scale/abs(deviation) beyond, and return median + sum(w*dev)/sum(w). Return 0.0 for empty data and the median when the scale or total weight is zero.
Hint
This is a single iteratively reweighted least squares update.
Test cases
case 1
in: [[1,2,3,4,5],1.345]
expected: 3
case 2
in: [[1,2,3,10,11],1.345]
expected: 4.223220825333151
case 3
in: [[5,5,5],1.345]
expected: 5
case 4
in: [[],1.345]
expected: 0
case 5
in: [[1,2,3,4,100],1.345]
expected: 3
Starter codePython
def huber_one_step(data, c):
# Your code here
pass5 test cases · run your code against them in the editor