All problems
Uplift Gain at Fraction
Problem
Compute the uplift gain of the top fraction of a ranked list. Sort by predicted uplift descending (ties by index), take the top k = max(1, int(n * fraction)) samples, and subtract the overall treated-minus-control response difference from the top-k difference; a treatment group missing from the top k contributes a 0.0 rate. Return 0.0 for invalid fractions or a missing treatment group.
Hint
Gain measures how much better the top-ranked segment responds compared with treating everyone at random.
Test cases
case 1
in: [[1,0,1,0],[1,1,0,1],[0.9,0.8,0.7,0.6],0.5]
expected: 0.5
case 2
in: [[1,0,1,0],[1,1,0,1],[0.1,0.2,0.3,0.4],0.5]
expected: -0.5
case 3
in: [[1,1,0,0],[1,0,1,0],[0.9,0.1,0.8,0.2],0.5]
expected: 0
case 4
in: [[1,1,0,0],[1,0,1,0],[0.9,0.1,0.8,0.2],0]
expected: 0
case 5
in: [[],[],[],0.5]
expected: 0
Starter codePython
def uplift_gain_at_fraction(treatment, outcome, uplift_scores, fraction):
# Your code here
pass5 test cases · run your code against them in the editor