1 Definition and intuition
Macro-averaging is a technique for summarizing model evaluation across multiple classes (or groups) by computing a chosen metric separately for each class and then averaging those per-class values without regard to the number of instances in each class. Because the final score is an unweighted mean across classes, each class contributes equally to the aggregate result.
1.1 Per-class metric computation
For classification tasks, a metric such as precision, recall, or F1-score is computed “as if” each class were the positive class in a binary scenario. The model’s outcomes for that class are summarized into per-class counts (commonly true positives, false positives, and false negatives), from which the selected metric is derived.
1.2 Unweighted averaging across classes
Once per-class metric values are obtained, macro-averaging aggregates them by taking the arithmetic mean across all classes included in the evaluation. If there are \(K\) classes and the per-class metric values are \(m_1,\dots,m_K\), the macro-average is \(\frac{1}{K}\sum_{k=1}^K m_k\).
1.3 When macro-averaging is informative
Macro-averaging is most informative when the goal is to assess how well the model performs across the entire label set rather than optimizing for the majority class. It is also useful when the evaluator wants a measure that does not diminish the impact of rare classes, making systematic underperformance on those classes easier to detect.
1.4 Relationship to class imbalance
In imbalanced datasets, majority classes can dominate aggregate metrics that pool counts globally. Macro-averaging counteracts that effect by equalizing class contribution. As a result, macro scores often provide a more balanced picture of performance when class frequencies vary substantially.
2 Mathematical formulation
2.1 Macro-average of a generic metric
2.1.1 Notation for classes and per-class scores
Let the set of classes be \(\{1,\dots,K\}\). Suppose a metric \(m(k)\) is computed for class \(k\). The macro-average of that metric is \[ m_{\text{macro}}=\frac{1}{K}\sum_{k=1}^K m(k). \] In practice, the definition of \(m(k)\) depends on the metric family (precision, recall, F1), and may require conventions when denominators become zero.
2.2 Macro-averaged precision
Per-class precision for class \(k\) is typically \[ P_k=\frac{\text{TP}_k}{\text{TP}_k+\text{FP}_k}, \] where \(\text{TP}_k\) are instances correctly predicted as class \(k\), and \(\text{FP}_k\) are instances predicted as \(k\) but belonging to other classes. The macro-averaged precision is \[ P_{\text{macro}}=\frac{1}{K}\sum_{k=1}^K P_k. \]
2.3 Macro-averaged recall
Per-class recall for class \(k\) is typically \[ R_k=\frac{\text{TP}_k}{\text{TP}_k+\text{FN}_k}, \] where \(\text{FN}_k\) are instances of class \(k\) predicted as not-\(k\). The macro-averaged recall is \[ R_{\text{macro}}=\frac{1}{K}\sum_{k=1}^K R_k. \]
2.4 Macro-averaged F1-score
The per-class F1-score is the harmonic mean of per-class precision and recall: \[ F1_k=\frac{2P_kR_k}{P_k+R_k}, \] defined when \(P_k+R_k>0\) under an agreed-upon convention for special cases. The macro-averaged F1-score is \[ F1_{\text{macro}}=\frac{1}{K}\sum_{k=1}^K F1_k. \]
2.5 Edge cases (e.g., zero divisions)
Per-class precision may be undefined when a model predicts no instances of a class, making \(\text{TP}_k+\text{FP}_k=0\). Similarly, recall may be undefined when a class has no true instances in the evaluation set, making \(\text{TP}_k+\text{FN}_k=0\). Implementations handle these cases using conventions such as:
- setting the metric to 0 when the numerator is 0 and the denominator is 0 (common in some libraries),
- excluding that class from the average (less standard for “pure” macro-averaging),
- or using a user-specified policy.
These choices can affect reported macro values, especially when rare classes appear infrequently.
3 Connection to confusion matrix metrics
3.1 Deriving per-class scores from one-vs-rest views
A confusion matrix organizes counts of true versus predicted classes. For class \(k\), one-vs-rest reduces the multiclass problem to a binary one where:
- positives are instances with true label \(k\),
- negatives are all other instances.
From the corresponding row/column of the confusion matrix, per-class \(\text{TP}_k\), \(\text{FP}_k\), and \(\text{FN}_k\) can be computed, yielding \(P_k\), \(R_k\), and \(F1_k\).
3.2 One-vs-one vs one-vs-rest considerations
Many common metrics for multiclass classification are defined via one-vs-rest logic (treating each class against all others). One-vs-one decompositions pair classes and focus on the decision boundary between each pair, but macro-averaging as used for precision/recall/F1 typically assumes one-vs-rest per-class computations. If a workflow uses one-vs-one models internally, metric reporting still usually converts predictions back into a multiclass confusion matrix and then computes per-class one-vs-rest scores for aggregation.
3.3 Handling missing predictions for a class
When a class receives no predicted outputs, its precision denominator becomes zero. The confusion matrix then shows a zero column for that class (with respect to predictions). Macro-averaging remains well-defined only after selecting a rule for the undefined per-class metric. Different tools may treat this class as having precision 0, omit it, or apply a smoothing strategy; therefore, reproducibility requires documenting the convention.
4 Comparison with related averaging schemes
4.1 Micro-averaging
Micro-averaging aggregates contributions by summing the per-class counts first and then computing the metric from those totals. For precision and recall, this effectively weights each instance equally across the whole dataset, so frequent classes exert more influence. Micro-averaged metrics often align closely with overall accuracy in single-label settings, while macro-averaged metrics can diverge when class performance is uneven.
4.2 Weighted macro-averaging
Weighted macro-averaging keeps the per-class computation style of macro-averaging but weights each class by a quantity proportional to its support (e.g., the number of true instances). The result resembles a compromise between macro and micro averaging: rare classes contribute less than they do in unweighted macro, yet performance across classes is not entirely dominated by the most frequent label.
4.3 Macro-averaging vs balanced accuracy
Balanced accuracy is closely related to macro-averaged recall in multiclass classification. Specifically, balanced accuracy averages per-class recall over classes, using one-vs-rest recall values. Thus, macro-averaged recall can be interpreted as balanced accuracy under standard definitions. Macro-averaged precision and F1 generally do not coincide with balanced accuracy.
4.4 Effect of label frequency on each scheme
In general:
- Micro-averaging increases sensitivity to label frequency because it pools counts across all instances.
- Unweighted macro-averaging treats each label as equally important, making it sensitive to failures on rare classes.
- Weighted macro-averaging interpolates between the two, moderating how much frequency-driven dominance occurs.
5 Practical evaluation workflow
5.1 Choosing metrics to macro-average
Common practice is to macro-average precision, recall, and F1-score for multiclass problems. Selection depends on the intended emphasis:
- precision highlights issues with over-prediction,
- recall highlights missed detections,
- F1 balances both.
If the downstream task penalizes different error types unevenly, evaluators may prefer metrics that match that cost structure, but macro-averaging primarily addresses *how performance is aggregated*, not the underlying error cost.
5.2 Implementation patterns in common tooling
Many evaluation libraries provide built-in support for macro-averaging. Typical workflows include:
- specifying an averaging mode (macro, micro, weighted),
- selecting how to handle zero division,
- ensuring the set of classes included in the report matches the intended label set (e.g., all labels present in training vs only those present in the evaluation split).
Reproducibility benefits from recording the library version and parameters related to zero-division behavior.
5.3 Reporting conventions and rounding
Macro metrics are often reported as decimals between 0 and 1. Reporting frequently includes:
- the averaging type (e.g., macro F1),
- the number of classes considered,
- and any special handling for undefined cases.
Rounding should be consistent with the level of numeric stability required; small changes in per-class values can produce noticeable shifts after averaging across many classes.
5.4 Averaging across multiple runs or folds
When models are evaluated via cross-validation or multiple random seeds, macro-averaging can be applied in two ways:
- compute per-fold macro metrics and then average across folds,
- or aggregate predictions across folds before computing confusion-matrix-derived metrics (depending on how folds are merged).
The first approach is common because it keeps fold-level independence. The second may be used when one wants a single confusion matrix from all predictions, but care is needed to ensure class definitions and zero-division conventions remain consistent.
6 Variants and extensions
6.1 Macro-averaging with multilabel classification
In multilabel problems, each instance can have multiple true labels. Metrics like precision and recall are computed per label, often by treating each label as a separate binary classification target (present vs absent). Macro-averaging then averages the label-wise metric values, again making each label contribute equally regardless of how often it appears.
6.2 Macro-averaging for ranking-based metrics
For ranking tasks, some metrics (e.g., average precision-like measures, mean reciprocal rank per item type, or label-wise top-k accuracy) can be computed for each class or group and then macro-averaged. The central idea remains identical: compute a class-specific score and then take an unweighted mean across classes.
6.3 Macro-averaging for hierarchical labels
When labels have a hierarchy (e.g., categories with subcategories), per-class metrics may be computed at multiple levels of the taxonomy. Macro-averaging can be applied level-by-level to compare performance across broad groups and refine the analysis within subgroups. Care is needed to define how errors propagate across levels and how to interpret partial correctness.
6.4 Subject-grouped macro-averaging (fairness-style summaries)
Macro-averaging can also be used when “classes” correspond to demographic or other subject groups, producing group-wise performance summaries. Although similar in mechanism to class macro-averaging, this usage is typically framed as an assessment across groups rather than across model labels. In such reports, documenting group definitions and evaluation policies is especially important because the meaning of “equal contribution” depends on the chosen grouping.
7 Interpretation and pitfalls
7.1 Understanding what macro scores can hide
Macro-averaging provides a view of per-class performance but can obscure where errors concentrate. For example, a model might perform very well on a subset of classes and poorly on the rest; macro scores will average these effects without indicating variance across classes unless additional reporting is provided (e.g., per-class metric tables).
7.2 Sensitivity to rare classes
Because each class contributes equally, a single rare class with extremely low performance can significantly lower the macro score. This behavior is often desirable for diagnosis, but it can also make macro metrics look worse than users expect when the evaluation objective is primarily dominated by common classes.
7.3 Class taxonomy effects and label definition drift
Macro-averaging assumes stable label definitions. If labels are merged, split, or otherwise redefined between datasets or experiments, macro scores may not be directly comparable. Even when the modeling pipeline remains unchanged, changes in what constitutes a “class” affect the set over which the unweighted mean is taken.
7.4 Misuse: averaging non-comparable metrics
Macro-averaging should only be applied when per-class metric values are computed consistently and are comparable in scale. Averaging metric variants computed under different assumptions (e.g., different averaging policies, incompatible thresholding, or differing label inclusion rules) can produce misleading results. Ensuring that each \(m(k)\) uses the same formula and evaluation conventions is essential.
8 Worked examples
8.1 Example with three classes (precision/recall)
Suppose a model is evaluated on three classes \(A\), \(B\), and \(C\). Per-class precisions are:
- \(P_A = 0.80\)
- \(P_B = 0.60\)
- \(P_C = 0.40\)
The macro-averaged precision is \[ P_{\text{macro}}=\frac{0.80+0.60+0.40}{3}=0.60. \] If per-class recalls are \(R_A=0.50\), \(R_B=0.70\), and \(R_C=0.30\), then \[ R_{\text{macro}}=\frac{0.50+0.70+0.30}{3}=0.50. \] F1-score macro-averaging would follow by computing \(F1_A, F1_B, F1_C\) and then taking their mean.
8.2 Example with imbalanced support sizes
Consider a dataset with 900 instances of \(A\), 90 of \(B\), and 10 of \(C\). Suppose the model predicts \(A\) correctly most of the time but struggles on \(C\). In such a case:
- micro-averaged metrics will be heavily influenced by the many \(A\) instances,
- macro-averaged metrics will reflect the poor performance on \(C\) almost as strongly as the performance on \(A\).
This difference illustrates why macro-averaging is frequently chosen when class-level fairness of performance is desired.
8.3 Example showing macro vs micro divergence
Assume three classes with per-class recalls:
- \(R_A=0.90\)
- \(R_B=0.20\)
- \(R_C=0.20\)
If the class supports are \(A:100\), \(B:10\), \(C:10\), then micro recall (equivalently, overall correct rate in one-vs-rest pooling) will be dominated by \(A\), producing a value closer to 0.8 or 0.9 depending on error distribution. Macro recall, however, becomes \[ R_{\text{macro}}=\frac{0.90+0.20+0.20}{3}=0.43, \] revealing a pronounced imbalance in per-class performance that micro averaging can conceal.
8.4 Example with a class having no predicted instances
Suppose class \(C\) is never predicted. Then the per-class precision \(P_C\) is undefined due to \(\text{TP}_C+\text{FP}_C=0\). If the evaluation tool uses a convention that sets undefined precision to 0, and the other class precisions are \(P_A=0.8\) and \(P_B=0.6\), then: \[ P_{\text{macro}}=\frac{0.8+0.6+0}{3}=0.466\overline{6}. \] If instead the tool excludes that class from the macro average, the reported number would be \(\frac{0.8+0.6}{2}=0.7\). The example highlights that macro-averaging with zero-prediction classes depends on explicit handling rules.