Skip to content
DeepForgeby svx
All problems
MediumML Fundamentalsml-242

Sensitivity at Specificity

Problem

Find the threshold with the highest sensitivity subject to specificity >= target_specificity. Sweep unique probabilities from high to low.

Return [threshold, sensitivity]; ties keep the higher threshold, and [0.0, 0.0] when nothing qualifies.

Hint

Trading specificity for sensitivity traces the ROC curve from the conservative end.

Test cases

case 1
in: [[0,0,1,1],[0.1,0.4,0.35,0.8],1]
expected: [0.8,0.5]
case 2
in: [[0,0,1,1],[0.1,0.4,0.35,0.8],0.5]
expected: [0.35,1]
case 3
in: [[1,1],[0.2,0.8],1]
expected: [0,0]
case 4
in: [[],[],1]
expected: [0,0]
Starter codePython
def sensitivity_at_specificity(y_true, probs, target_specificity):
    # Returns [threshold, sensitivity]
    # Your code here
    pass

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