espnet2.utils.eer.tuneThresholdfromScore
Less than 1 minute
espnet2.utils.eer.tuneThresholdfromScore
espnet2.utils.eer.tuneThresholdfromScore(scores, labels, target_fa, target_fr=None)
Tunes the decision threshold based on given scores and labels to achieve desired
false acceptance and false rejection rates. This function calculates the optimal thresholds that minimize the differences between target false positive rates (FPR) and false negative rates (FNR).
- Parameters:
- scores (list or numpy.ndarray) – A list or array of scores to evaluate.
- labels (list or numpy.ndarray) – A list or array of ground truth labels (0 or 1).
- target_fa (list) – A list of target false acceptance rates.
- target_fr (list , optional) – A list of target false rejection rates. If not provided, only target_fa will be used for tuning.
- Returns: A tuple containing: : - tunedThreshold (list): A list of thresholds and corresponding FPR and FNR values.
- eer (float): The equal error rate (EER) expressed as a percentage.
- fpr (numpy.ndarray): The array of false positive rates.
- fnr (numpy.ndarray): The array of false negative rates.
- Return type: tuple
Examples
>>> scores = [0.1, 0.4, 0.35, 0.8]
>>> labels = [0, 0, 1, 1]
>>> target_fa = [0.1]
>>> tuned_threshold, eer, fpr, fnr = tuneThresholdfromScore(scores, labels,
... target_fa)
>>> print(tuned_threshold)
[[0.4, 0.1, 0.5], ...] # Example output
NOTE
This function relies on the sklearn library for ROC curve computation and assumes that the input scores are continuous values.