Refactor hierarchical_precision_recall_fmeasure function***
Browse files
ham.py
CHANGED
@@ -30,20 +30,3 @@ def hierarchical_precision_recall_fmeasure(
|
|
30 |
hF = ((beta**2 + 1) * hP * hR) / (beta**2 * hP + hR) if (hP + hR) else 0
|
31 |
|
32 |
return hP, hR, hF
|
33 |
-
|
34 |
-
|
35 |
-
# Example usage:
|
36 |
-
true_labels = [{"G"}] # The true class for the instance
|
37 |
-
predicted_labels = [{"F"}] # The predicted class for the instance
|
38 |
-
ancestors = { # The ancestors for each class, excluding the root
|
39 |
-
"G": {"B", "C", "E"},
|
40 |
-
"F": {"C"},
|
41 |
-
}
|
42 |
-
|
43 |
-
# Calculate hierarchical measures
|
44 |
-
hP, hR, hF = hierarchical_precision_recall_fmeasure(
|
45 |
-
true_labels, predicted_labels, ancestors
|
46 |
-
)
|
47 |
-
print(f"Hierarchical Precision (hP): {hP}")
|
48 |
-
print(f"Hierarchical Recall (hR): {hR}")
|
49 |
-
print(f"Hierarchical F-measure (hF): {hF}")
|
|
|
30 |
hF = ((beta**2 + 1) * hP * hR) / (beta**2 * hP + hR) if (hP + hR) else 0
|
31 |
|
32 |
return hP, hR, hF
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|