Explore Library
Code QuizIntermediate

Macro vs Weighted F1 Average

Choosing the right averaging mode when reporting multiclass F1 on imbalanced data.

Codepython
from sklearn.metrics import f1_score

y_true = [0, 0, 0, 0, 0, 0, 0, 0, 1, 2]
y_pred = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

# Report a class-frequency-weighted F1
score = f1_score(y_true, y_pred, average='macro')
print(score)

The comment says the score should be weighted by class frequency. What is the bug?