All problems
Propensity Trimming Fraction
Problem
Compute the fraction of propensity scores that need trimming: those strictly below epsilon or strictly above 1 - epsilon. Empty input returns 0.0.
Hint
Extreme propensities produce enormous weights, so samples near 0 or 1 are often dropped.
Test cases
case 1
in: [[0.5,0.1,0.95,0.9],0.15]
expected: 0.75
case 2
in: [[0.5,0.5],0.1]
expected: 0
case 3
in: [[],0.1]
expected: 0
case 4
in: [[0,1],0]
expected: 0
case 5
in: [[0.05,0.95],0.1]
expected: 1
Starter codePython
def trimmed_propensity_fraction(propensities, epsilon):
# Your code here
pass5 test cases · run your code against them in the editor