Pick the lowest safe threshold for duplicate suggestions
Your task
Your bug tracker is full of duplicates. An agent suggests duplicates for a person to merge, and a wrong merge buries a real bug, so you set the agent's confidence threshold from labeled history.
Write choose_suggest_threshold(scores, is_duplicate, min_precision_pct): the calculation that picks the threshold.
scores(list of int): the agent's confidence for each past pair of bugs, from 0 to 100.is_duplicate(list of bool): whether that pair really was a duplicate.min_precision_pct(int): the lowest acceptable precision, in percent. Precision is the share of suggestions that are real duplicates.- Return the threshold.
Rules:
- Index
iin each list is one pair. Stop at the end of the shorter list. - At a threshold
t, the agent suggests every pair with a score of at leastt. - Return the smallest whole number
tfrom 0 to 100 that passes. A threshold passes when the agent suggests at least one pair andcorrect * 100 >= min_precision_pct * suggested. Heresuggestedis how many pairs it suggests, andcorrectis how many of those are real duplicates. - If no such
texists: return 101, meaning never suggest.
Examples
choose_suggest_threshold(scores: list[int], is_duplicate: list[bool], min_precision_pct: int) -> intExample 1
Input
choose_suggest_threshold([90, 80, 95, 60, 99], [True, False, True, False, True], 95)Output
81Example 2
Input
choose_suggest_threshold([90, 80, 95, 60, 99], [True, False, True, False, True], 60)Output
0Example 3
Input
choose_suggest_threshold([70, 40, 55], [False, False, False], 50)Output
101