Skip to content
DeepForgeby svx
All problems
HardML Fundamentalsml-240

Threshold for Given Precision

Problem

Find the threshold with the highest recall subject to precision >= target. Sweep unique probabilities from high to low.

Return the threshold (0.0 if none qualifies), with ties keeping the higher threshold.

Hint

Lower thresholds raise recall but erode precision; pick the most permissive feasible one.

Test cases

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

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