All problems
Macro F1 Score
Problem
Compute macro-averaged F1 across the classes present in y_true.
For each class compute precision, recall, and F1 = 2*p*r/(p+r), using 0.0 whenever a denominator is zero. Return the unweighted mean of the per-class F1 values. Empty input returns 0.0.
Hint
Treat each class as positive versus the rest, then average the F1 scores equally.
Test cases
case 1
in: [[0,1,2,0,1,2],[0,1,2,0,1,2]]
expected: 1
case 2
in: [[0,0,1,1,2,2],[0,1,1,2,2,0]]
expected: 0.5
case 3
in: [[0,1,0,1],[1,0,1,0]]
expected: 0
case 4
in: [[0,0,0],[0,0,1]]
expected: 0.8
Starter codePython
def macro_f1(y_true, y_pred):
# Your code here
pass4 test cases · run your code against them in the editor