mfajcik commited on
Commit
f4e212f
β€’
1 Parent(s): bfab51a

Update mc_auroc.py

Browse files
Files changed (1) hide show
  1. mc_auroc.py +16 -15
mc_auroc.py CHANGED
@@ -85,7 +85,7 @@ class AVG_MULTICLASS_AUROC(evaluate.Metric):
85
 
86
  return lower, upper
87
 
88
- def _compute(self, predictions: Sequence[Sequence[float]], references: Sequence[int]):
89
  """
90
  Computes the average AUROC score for multi-class classification problems.
91
  """
@@ -102,17 +102,17 @@ class AVG_MULTICLASS_AUROC(evaluate.Metric):
102
  fpr[i], tpr[i], thresholds[i] = roc_curve(y_true=[1 if x == n_classes[i] else 0 for x in references],
103
  y_score=[prob[i] for prob in probabilities])
104
 
105
- confusion_matrices = self._get_CMs(i, probabilities, references, thresholds)
106
-
107
- low_ci_tpr, high_ci_tpr = [0] * len(thresholds[i]), [0] * len(thresholds[i])
108
- Ξ» = 1.0
109
- for k in range(len(thresholds[i])):
110
- variates = numpy.random.beta(confusion_matrices[k]["TP"] + Ξ», confusion_matrices[k]["FN"] + Ξ», 1000000)
111
- low_ci_tpr[k], high_ci_tpr[k] = self._evaluate_statistics(variates, 0.95)
112
-
113
- roc_auc_ci_low[i] = auc(fpr[i], low_ci_tpr)
114
- roc_auc_ci_high[i] = auc(fpr[i], high_ci_tpr)
115
-
116
 
117
 
118
  roc_auc[i] = auc(fpr[i], tpr[i])
@@ -123,12 +123,13 @@ class AVG_MULTICLASS_AUROC(evaluate.Metric):
123
 
124
  # Compute average AUC
125
  average_auc = numpy.mean(list(roc_auc.values()))
126
- average_auc_ci_low = numpy.mean(list(roc_auc_ci_low.values()))
127
- average_auc_ci_high = numpy.mean(list(roc_auc_ci_high.values()))
 
128
 
129
  return {
130
  "mc_auroc_score": average_auc,
131
- "mc_auroc_ci": (average_auc_ci_low, average_auc_ci_high)
132
  }
133
 
134
  def _get_CMs(self, i, probabilities, references, thresholds):
 
85
 
86
  return lower, upper
87
 
88
+ def _compute(self, predictions: Sequence[Sequence[float]], references: Sequence[int], CI=False):
89
  """
90
  Computes the average AUROC score for multi-class classification problems.
91
  """
 
102
  fpr[i], tpr[i], thresholds[i] = roc_curve(y_true=[1 if x == n_classes[i] else 0 for x in references],
103
  y_score=[prob[i] for prob in probabilities])
104
 
105
+ if CI:
106
+ confusion_matrices = self._get_CMs(i, probabilities, references, thresholds)
107
+
108
+ low_ci_tpr, high_ci_tpr = [0] * len(thresholds[i]), [0] * len(thresholds[i])
109
+ Ξ» = 1.0
110
+ for k in range(len(thresholds[i])):
111
+ variates = numpy.random.beta(confusion_matrices[k]["TP"] + Ξ», confusion_matrices[k]["FN"] + Ξ», 1000000)
112
+ low_ci_tpr[k], high_ci_tpr[k] = self._evaluate_statistics(variates, 0.95)
113
+
114
+ roc_auc_ci_low[i] = auc(fpr[i], low_ci_tpr)
115
+ roc_auc_ci_high[i] = auc(fpr[i], high_ci_tpr)
116
 
117
 
118
  roc_auc[i] = auc(fpr[i], tpr[i])
 
123
 
124
  # Compute average AUC
125
  average_auc = numpy.mean(list(roc_auc.values()))
126
+ if CI:
127
+ average_auc_ci_low = numpy.mean(list(roc_auc_ci_low.values()))
128
+ average_auc_ci_high = numpy.mean(list(roc_auc_ci_high.values()))
129
 
130
  return {
131
  "mc_auroc_score": average_auc,
132
+ "mc_auroc_ci": (average_auc_ci_low, average_auc_ci_high) if CI else None
133
  }
134
 
135
  def _get_CMs(self, i, probabilities, references, thresholds):