Refactor hierarchical measures calculation in MetricTemplate1.py
Browse files- metric_template_1.py +8 -11
metric_template_1.py
CHANGED
@@ -102,18 +102,15 @@ class MetricTemplate1(evaluate.Metric):
|
|
102 |
predictions
|
103 |
)
|
104 |
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
}
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
)
|
114 |
-
print(f"Hierarchical Precision (hP): {hP}")
|
115 |
-
print(f"Hierarchical Recall (hR): {hR}")
|
116 |
-
print(f"Hierarchical F-measure (hF): {hF}")
|
117 |
|
118 |
return {
|
119 |
"accuracy": accuracy,
|
|
|
102 |
predictions
|
103 |
)
|
104 |
|
105 |
+
# Example usage:
|
106 |
+
hierarchy = {"G": ["E"], "E": ["B"], "F": ["C"], "C": ["B"], "B": []}
|
107 |
+
# true_labels = [{'G'}]
|
108 |
+
# predicted_labels = [{'F'}]
|
109 |
+
hP, hR = ham.hierarchical_precision_recall(references, predictions, hierarchy)
|
110 |
+
hF = ham.hierarchical_f_measure(hP, hR)
|
111 |
+
print(
|
112 |
+
f"Hierarchical Precision: {hP}, Hierarchical Recall: {hR}, Hierarchical F-measure: {hF}"
|
113 |
)
|
|
|
|
|
|
|
114 |
|
115 |
return {
|
116 |
"accuracy": accuracy,
|