Skip to content
DeepForgeby svx
All problems
MediumML Fundamentalsml-241

Threshold for Given Recall

Problem

Find the highest threshold whose recall is at least target. Sweep unique probabilities from high to low and return the first feasible threshold.

Return 0.0 if none qualifies or there are no positive labels.

Hint

A higher threshold is preferable when it still meets the recall requirement.

Test cases

case 1
in: [[0,0,1,1],[0.1,0.4,0.35,0.8],1]
expected: 0.35
case 2
in: [[0,0,1,1],[0.1,0.4,0.35,0.8],0.5]
expected: 0.8
case 3
in: [[0,0,1,1],[0.1,0.4,0.35,0.8],0.6]
expected: 0.35
case 4
in: [[0,0],[0.1,0.9],0.5]
expected: 0
Starter codePython
def threshold_for_recall(y_true, probs, target):
    # Your code here
    pass

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