Spaces:
Sleeping
Sleeping
helena-balabin
commited on
Commit
•
85b419a
1
Parent(s):
32b67df
Fix the calculation of the optimal predictions
Browse files- youden_index.py +3 -3
youden_index.py
CHANGED
@@ -107,11 +107,11 @@ class YoudenIndex(evaluate.Metric):
|
|
107 |
# 1. Compute ROC AUC
|
108 |
roc_auc = roc_auc_score(references, prediction_scores)
|
109 |
# 2. Determine the optimal threshold based on the Youden index
|
110 |
-
fpr, tpr, thresholds = roc_curve(references, prediction_scores)
|
111 |
idx = np.argmax(tpr - fpr)
|
112 |
-
optimal_threshold = thresholds[idx
|
113 |
# 3. Calculate PPV (precision) and NPV based on the optimal threshold
|
114 |
-
optimal_predictions = np.where(prediction_scores
|
115 |
ppv = precision_score(references, optimal_predictions)
|
116 |
npv = precision_score(references, optimal_predictions, pos_label=0)
|
117 |
return {
|
|
|
107 |
# 1. Compute ROC AUC
|
108 |
roc_auc = roc_auc_score(references, prediction_scores)
|
109 |
# 2. Determine the optimal threshold based on the Youden index
|
110 |
+
fpr, tpr, thresholds = roc_curve(references, prediction_scores, drop_intermediate=False)
|
111 |
idx = np.argmax(tpr - fpr)
|
112 |
+
optimal_threshold = thresholds[idx]
|
113 |
# 3. Calculate PPV (precision) and NPV based on the optimal threshold
|
114 |
+
optimal_predictions = np.where(prediction_scores >= optimal_threshold, 1, 0)
|
115 |
ppv = precision_score(references, optimal_predictions)
|
116 |
npv = precision_score(references, optimal_predictions, pos_label=0)
|
117 |
return {
|