Notes

Per-Class Metrics

When you build a classifier, it’s tempting to ask, “How accurate is it?” But in many real problems—fraud detection, disease screening, churn prediction—different classes matter in different ways, and a single score can hide serious failures. Per-class metrics keep you honest by showing performance separately for each class.

What per-class metrics are

Per-class metrics report evaluation numbers for each label in a multi-class or binary classification problem, treating one class at a time as the “positive” class and the rest as “negative” (a one-vs-rest view). Common per-class metrics come from the class-specific confusion counts: TP, FP, FN, TN. From these you compute:

  • Precision (per class): of the items predicted as this class, how many were correct?
  • Recall / Sensitivity (per class): of the true items of this class, how many did you catch?
  • F1-score (per class): balances precision and recall for that class.
  • Specificity (per class): how well you reject “not-this-class.”

Why they matter for imbalanced data

With class imbalance, overall accuracy can look great while the minority class is ignored. Example: in credit-card fraud (0.2% fraud), a model that predicts “not fraud” for everything gets 99.8% accuracy but recall for the fraud class is 0. Per-class metrics reveal exactly which class is being sacrificed, and they connect directly to cost: missing fraud (low recall) vs flagging legitimate purchases (low precision).

How you’ll see them in practice

In scikit-learn, classification_report prints per-class precision/recall/F1, and precision_recall_fscore_support returns them programmatically:

from sklearn.metrics import classification_report

print(classification_report(y_true, y_pred))

These per-class numbers also underpin macro/weighted averages, but the per-class view is the part that tells you what your model is really doing to each group of cases.

Per-Class Metrics are evaluation measures computed separately for each class in a supervised classification problem, such as class-specific precision, recall, F1-score, and specificity, derived from one-vs-rest confusion counts. They expose how performance differs across classes instead of collapsing results into a single aggregate score. This matters in imbalanced or cost-sensitive settings because overall accuracy can hide severe errors on minority or high-cost classes.

Imagine a teacher grading a class where most students are doing fine, but a few are really struggling. If the teacher only reports the class average, it can hide the fact that those few students need help. Per-Class Metrics do the same kind of “separate report card” for an AI model: they measure how well the model performs for each category on its own.

This matters a lot when some categories are rare, like fraud vs. normal purchases or a rare disease vs. healthy cases. A model can look great overall but still miss most fraud or rare disease cases. Per-Class Metrics make those blind spots visible.