Spaces:
Runtime error
Runtime error
Update multiclass_sensitivity_weighted.py
Browse files
multiclass_sensitivity_weighted.py
CHANGED
@@ -87,36 +87,7 @@ class multiclass_sensitivity_weighted(evaluate.Metric):
|
|
87 |
pass
|
88 |
|
89 |
def _compute(self, predictions, references):
|
90 |
-
from
|
91 |
-
"""Returns the scores"""
|
92 |
-
# TODO: Compute the different scores of the module
|
93 |
-
# Count true positives, false negatives, and true instance counts for each class
|
94 |
-
tp_counts = defaultdict(int)
|
95 |
-
fn_counts = defaultdict(int)
|
96 |
-
true_counts = defaultdict(int)
|
97 |
-
|
98 |
-
for true_label, pred_label in zip(references, predictions):
|
99 |
-
true_counts[true_label] += 1
|
100 |
-
if true_label == pred_label:
|
101 |
-
tp_counts[true_label] += 1
|
102 |
-
else:
|
103 |
-
fn_counts[true_label] += 1
|
104 |
-
|
105 |
-
# Calculate class-wise sensitivity
|
106 |
-
class_sensitivities = {}
|
107 |
-
total_weight = sum(true_counts.values())
|
108 |
-
weighted_sum = 0.0
|
109 |
-
|
110 |
-
for class_label in set(references):
|
111 |
-
tp = tp_counts[class_label]
|
112 |
-
fn = fn_counts[class_label]
|
113 |
-
true_instances = true_counts[class_label]
|
114 |
-
|
115 |
-
sensitivity = tp / (tp + fn) if (tp + fn) > 0 else 0
|
116 |
-
class_sensitivities[class_label] = sensitivity
|
117 |
-
weighted_sum += sensitivity * true_instances
|
118 |
-
|
119 |
-
weighted_avg_sensitivity = weighted_sum / total_weight if total_weight > 0 else 0
|
120 |
return {
|
121 |
-
"weighted_sensitivity":
|
122 |
}
|
|
|
87 |
pass
|
88 |
|
89 |
def _compute(self, predictions, references):
|
90 |
+
from imblearn.metrics import sensitivity_score
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
return {
|
92 |
+
"weighted_sensitivity": sensitivity_score(references, predictions, average = "weighted")
|
93 |
}
|