All problems
Propensity Weight Trim
Problem
Return the propensity weights with every value above cap replaced by cap. Return a list of zeros when cap <= 0.
Hint
Trimming extreme weights limits variance at the cost of some bias.
Test cases
case 1
in: [[0.5,1.5,2],1]
expected: [0.5,1,1]
case 2
in: [[1,2],5]
expected: [1,2]
case 3
in: [[],1]
expected: []
case 4
in: [[3,3],0]
expected: [0,0]
case 5
in: [[0.2,0.4],0.3]
expected: [0.2,0.3]
Starter codePython
def trim_weights(weights, cap):
# Your code here
pass5 test cases · run your code against them in the editor