What is macro averaging in multiclass evaluation?
Macro averaging evaluates a multiclass classifier by calculating a metric separately for each class and then taking the ordinary (unweighted) mean of those class scores.
It gives every class equal influence, regardless of whether a class contains thousands of examples or only a few.
How does it work?
For a metric such as precision, recall, or F1-score:
- Treat each class in turn as the positive class and all other classes as negative (one-versus-rest).
- Compute the metric for each class.
- Add the per-class results and divide by the number of classes.
Macro metric = (score_class_1 + ... + score_class_K) / KHere K is the number of evaluated classes. Macro F1 means averaging the individual class F1-scores; it is *not* generally the F1 calculated from macro precision and macro recall.
Beginner-friendly numerical example
Imagine an eight-photo classifier with three categories: Cat, Dog, and Bird.
- Actual: Cat, Cat, Cat, Cat, Dog, Dog, Bird, Bird
- Predicted: Cat, Cat, Cat, Cat, Cat, Dog, Dog, Bird
Treat each class as positive in turn:
- Cat: TP=4, FP=1, FN=0. Precision=4/5=0.80; recall=4/4=1.00; F1=8/9≈0.889.
- Dog: TP=1, FP=1, FN=1. Precision=1/2=0.50; recall=1/2=0.50; F1=0.500.
- Bird: TP=1, FP=0, FN=1. Precision=1/1=1.00; recall=1/2=0.50; F1=2/3≈0.667.
Now average the three F1-scores:
Macro F1 = (8/9 + 1/2 + 2/3) / 3
= 37/54
≈ 0.685 (68.5%)All three classes contribute one-third to the final macro score. Even though the model correctly classifies all four cats, it cannot hide weaker performance on dogs or birds.
Python example
PYTHONfrom sklearn.metrics import f1_score, precision_score, recall_score y_true = ["cat"]*4 + ["dog"]*2 + ["bird"]*2 y_pred = ["cat"]*5 + ["dog", "dog", "bird"] print("Macro precision:", round( precision_score(y_true, y_pred, average="macro"), 3 )) # 0.767 print("Macro recall:", round( recall_score(y_true, y_pred, average="macro"), 3 )) # 0.667 print("Macro F1:", round( f1_score(y_true, y_pred, average="macro"), 3 )) # 0.685
When is macro averaging useful?
- Imbalanced classes: when a rare category matters as much as a common one.
- Fair class-level assessment: when you want to see whether the classifier performs reasonably across every label.
- Model comparison: when business requirements value per-class performance rather than only total correct predictions.
Common pitfalls
- It does not account for class frequency. Poor results on a very rare class can heavily affect the overall score, even if that class is not operationally important.
- Always inspect per-class scores too. A single macro number can still conceal one badly performing class.
- Undefined per-class metrics require a policy. In scikit-learn,
zero_divisioncontrols cases such as no positive predictions. - Do not confuse macro with weighted or micro averaging. Those use class support or pooled counts and are covered in the next curriculum question.
In short: macro averaging gives one equal vote to each class, making it especially useful when minority-class performance should not be drowned out by majority classes.
References
Learning Sequence
Machine Learning Curriculum
What is micro averaging in multiclass evaluation?
Explore Related Questions
Deepen your understanding across related Machine Learning topics.