danieldux commited on
Commit
3894697
1 Parent(s): 8b7a053

Refactor hierarchical measures calculation in MetricTemplate1.py

Browse files
Files changed (1) hide show
  1. metric_template_1.py +8 -11
metric_template_1.py CHANGED
@@ -102,18 +102,15 @@ class MetricTemplate1(evaluate.Metric):
102
  predictions
103
  )
104
 
105
- ancestors = { # The ancestors for each class, excluding the root
106
- "G": {"B", "C", "E"},
107
- "F": {"C"},
108
- }
109
-
110
- # Calculate hierarchical measures
111
- hP, hR, hF = ham.hierarchical_precision_recall_fmeasure(
112
- references, predictions, ancestors
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,