Skip to content
DeepForgeby svx
All problems
HardML Fundamentalsml-231

KS Statistic from Scores

Problem

Compute the KS statistic from a binary label list and scores: the maximum absolute gap between the cumulative TPR and FPR over all thresholds.

Return 0.0 when the input is empty or a class is missing.

Hint

KS is the maximum separation between the TPR and FPR curves.

Test cases

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

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