What is weighted averaging in multiclass evaluation?
What is weighted averaging in multiclass evaluation?
Weighted averaging summarizes a multiclass precision, recall, or F1-score by giving each class a weight proportional to its support—the number of true examples belonging to that class.
How is it calculated?
- Find each class's precision, recall, or F1-score.
- Count its support (actual examples of that class).
- Multiply its metric by its support, add across classes, and divide by the total support.
Weighted metric = Σ(class metric × class support) / Σ(class support).
Beginner-friendly numerical example
A classifier predicts the labels Cat, Dog, and Bird for 100 photographs:
- Cat: support 70, F1 = 0.90
- Dog: support 20, F1 = 0.70
- Bird: support 10, F1 = 0.40
Weighted F1 = (70 × 0.90 + 20 × 0.70 + 10 × 0.40) / 100 = (63 + 14 + 4) / 100 = 0.81.
This illustrates the weighting arithmetic with illustrative per-class scores. In practice, compute the scores from predictions, then weight them by observed class support.
Why use it?
- It reflects the dataset's actual class distribution.
- It provides one summary when common categories contribute more examples.
- It can be useful for monitoring overall model performance on imbalanced datasets.
Important limitations
- A high weighted score can hide weak performance on a rare but important class—here Bird's F1 is only 0.40.
- Weighted recall equals accuracy in ordinary single-label multiclass classification when all labels are included; weighted precision and weighted F1 do not generally equal accuracy.
- Weighted F1 is not necessarily the harmonic mean of weighted precision and weighted recall, because each class's F1 is computed first and then averaged.
- If classes have different *business costs*, class support alone does not capture those costs. Check per-class results and consider cost-sensitive evaluation.
Python example
PYTHONfrom sklearn.metrics import precision_recall_fscore_support precision, recall, f1, support = precision_recall_fscore_support( y_true, y_pred, average="weighted", zero_division=0 ) print(f"Weighted F1: {f1:.3f}")
With average="weighted", the returned support value is None; per-class support is available with average=None.
Remember: Weighted averaging answers, “How well does the model perform when classes contribute in proportion to how frequently they appear in the test set?”
Reference: scikit-learn precision_recall_fscore_support.
Sources & Research References
Learning Sequence
Machine Learning Curriculum
What is a confusion matrix in multiclass classification?
Explore Related Questions
Deepen your understanding across related Machine Learning topics.