All problems
Winsorized Mean
Problem
Return the mean of the winsorized data: sort the values, replace the k smallest with the (k+1)-th smallest and the k largest with the (k+1)-th largest, then average. If 2*k >= n use the median and if k <= 0 use the ordinary mean. Return 0.0 for empty input.
Hint
This is the mean of the winsorized list.
Test cases
case 1
in: [[1,2,3,4,5,100],1]
expected: 3.5
case 2
in: [[1,2,3,4],1]
expected: 2.5
case 3
in: [[1,2,3,4],0]
expected: 2.5
case 4
in: [[1,10],1]
expected: 5.5
case 5
in: [[],1]
expected: 0
Starter codePython
def winsorized_mean(data, k):
# Your code here
pass5 test cases · run your code against them in the editor