Precision Floor Threshold

Start Timer

0:00:00

Upvote
0
Downvote
Save question
View comments

Given scores, a list of validation-set model scores, and labels, the matching binary labels (1 for the positive driver class, 0 otherwise), write a function pick_threshold that returns the decision threshold maximizing recall subject to precision being at least min_precision. A prediction is positive when score >= threshold, and only distinct observed scores are candidate thresholds, so tied scores are always assigned the same prediction.

Among feasible thresholds, prefer the one with highest recall, then break ties by higher precision, then by the larger threshold value. Return None if no threshold meets the precision floor.

Example:

Input:

scores = [0.9, 0.8, 0.8, 0.4, 0.2]
labels = [1,   1,   0,   1,   0]
min_precision = 0.6

Output:

pick_threshold(scores, labels, 0.6) -> 0.4

At threshold 0.4 we predict positive on scores 0.9, 0.8, 0.8, 0.4: 3 of 4 are positive (precision 0.75 >= 0.6) and we catch all 3 positives (recall 1.0).

Assume equally sized lists, finite scores, binary labels, and 0 <= min_precision <= 1. Require at least one positive prediction; return None for empty input or no positive labels. These exact search rules and examples are practice assumptions adapting the reported validation-threshold task.

.
.
.
.
.


Comments

Loading comments