Macro Precision#
The unweighted mean of per-class precision values.
Important
✨ AI-generated content. This page was written with the assistance of an AI language model and is provided as a learning aid. Despite careful review, it may still contain mistakes, omissions, or out-of-date information. Whether you are new to the topic, a team lead, or a senior practitioner, treat it as a starting point rather than an authoritative reference: read it critically and independently verify anything you act on (code, commands, figures, and factual claims) against official documentation and primary sources before relying on it.
What it is#
Precision is the share of the model’s positive predictions that are correct, \(\text{Precision} = TP/(TP+FP)\), so it is sensitive to false positives. For \(K\) classes, compute precision per class (one-vs-rest) and take the arithmetic mean to get macro precision:
Every class counts equally, whatever its size, so a small class the model over-flags pulls the score down as much as a large one.
Macro vs micro vs weighted#
Macro — equal weight per class; fair across classes.
Micro — pool global TP and FP first; dominated by large classes (and equals accuracy in single-label problems).
Weighted — per-class precision averaged by class frequency.
Worked example#
Three classes with Precision(A)=0.80, Precision(B)=0.60, Precision(C)=0.40:
If C is tiny, macro precision still penalises weak performance on it.
Pitfalls and edge cases#
Zero-division — a class the model never predicts has 0 in the denominator; its precision is undefined and conventionally set to 0, which penalises ignoring the class. Set
zero_divisionexplicitly to control this.Pair it with recall — precision rewards being conservative; a model that rarely predicts a class can post high precision while missing most of it.
In code#
from sklearn.metrics import precision_score
macro = precision_score(y_true, y_pred, average="macro", zero_division=0)
weighted = precision_score(y_true, y_pred, average="weighted")
Theme: Classification & Averaging Metrics · All terminology
Hint
Mind map — connected ideas
Micro Precision · Macro Recall · Macro F1 · Macro AUROC (Macro-Averaged AUROC)
Hint
More in Classification & Averaging Metrics
Accuracy · AUC (Area Under the Curve) · Average Precision (AP) · Binary Classification · Classification Probability · Discriminatory Power · F1-score · Gini Coefficient · Harmonic Mean · Log Loss (also called Logarithmic Loss or Cross-Entropy Loss) · Macro AUC · Macro AUROC (Macro-Averaged AUROC) · Macro Averaging · Macro F1
See also
Source article Adapted (context, re-expressed) in our own words from: Macro Precision (insightful-data-lab.com).