Skip to content
DeepForgeby svx
All problems
MediumML Fundamentalsml-102

Lift at K

Problem

Compute lift at k: the precision among the k highest-scored samples divided by the overall positive rate.

Sort by score descending, breaking ties by the original index. Return 0.0 if k is not in [1, n], the base rate is 0, or the input is empty.

Hint

Lift compares top-k precision against what random selection would achieve.

Test cases

case 1
in: [[0,0,1,1],[0.1,0.4,0.8,0.9],2]
expected: 2
case 2
in: [[0,1,1,0],[0.9,0.8,0.2,0.1],1]
expected: 0
case 3
in: [[0,1,1,0],[0.9,0.8,0.2,0.1],2]
expected: 1
case 4
in: [[0,1,1,0],[0.9,0.8,0.2,0.1],5]
expected: 0
case 5
in: [[],[],1]
expected: 0
Starter codePython
def lift_at_k(y_true, scores, k):
    # Your code here
    pass

5 test cases · run your code against them in the editor