All problems
Cumulative Gains
Problem
Compute the cumulative gains curve: sort by score descending (ties by original index) and return the cumulative share of positives captured after each sample.
Return [] when there are no positive labels or the input is empty.
Hint
Gains rise fastest when the highest-scored samples are the true positives.
Test cases
case 1
in: [[0,0,1,1],[0.1,0.4,0.8,0.9]]
expected: [0.5,1,1,1]
case 2
in: [[1,0,1],[0.5,0.9,0.5]]
expected: [0,0.5,1]
case 3
in: [[0,0],[0.1,0.2]]
expected: []
case 4
in: [[],[]]
expected: []
Starter codePython
def cumulative_gains(y_true, scores):
# Your code here
pass4 test cases · run your code against them in the editor