Classification Metrics

Classification metrics compare a classifier’s outputs on a test set with the true labels. Most metrics are defined for two classes, called positive and negative. They extend to classes by treating each class in turn as positive. A probabilistic classifier gives each point a score or probability . A threshold turns it into a hard label , positive when . The metrics differ in which output they read:

  • Label metrics read only at one threshold. Accuracy, precision, recall and $F_1$ are ratios of the counts of true and false positives and negatives.
  • Ranking metrics read the order of the scores over all thresholds. ROC-AUC and average precision (PR-AUC) belong here.
  • Probability metrics read the values themselves. Log loss belongs here.

Accuracy and change with the threshold, whereas AUC-based metrics do not. Log loss needs no threshold, but it requires probabilities in .

The decision rule is as follows:

  • Accuracy only when the classes are roughly balanced and both kinds of error cost about the same.
  • Precision, recall and under class imbalance, once a threshold is fixed. replaces when misses and false alarms have different costs.
  • ROC-AUC by default to compare how well models rank positives above negatives, without choosing a threshold.
  • PR-AUC (average precision) instead of ROC-AUC when positives are rare and the top of the ranking matters.
  • Log loss when the predicted probabilities feed a decision, such as a price, a dose or an expected cost.

Intuition

Every metric in the family starts from the same scored test set. They differ in how much of the model’s output they use. A label metric uses one bit per point and describes the deployed system at its chosen threshold. A ranking metric uses the order of the scores. It describes how well the model separates the classes at any threshold. A probability metric uses the values and also checks whether a stated 30% risk comes true 30% of the time. A metric that reads more of the output can tell more models apart, and it demands more of the model.

A second axis is class balance. Recall and the false positive rate are each computed within one true class. ROC-AUC is built from these two rates. All three ignore the prevalence . Accuracy, precision, , average precision and log loss mix the classes, so they change with . Only the first group carries over unchanged from a test set to a deployment with a different base rate.

Comparison Table

MetricWhat it measuresNeeds a threshold?Range and chance levelSensitive to class balance?Default use
Accuracyfraction of correct labelsyes; always predicting the majority class gives yes, the majority class dominatesbalanced classes, equal error costs
Precision, recall, $F_1$fraction of flags that are right; fraction of positives caught; their harmonic meanyes; random flags give precision ; flagging everything gives precision and yes, recall noimbalanced classes at a fixed threshold
ROC-AUCprobability that a random positive outscores a random negativeno; nocomparing rankings when the prevalence may shift
PR-AUC (average precision)mean precision at the ranks of the positivesno; about yesrare positives, when the top of the ranking matters
Log lossaverage negative log-probability of the true labelno, it reads probabilities; for a constant , for a constant yes, through the baseline probabilities that feed decisions; calibration checks

When to Use Which

Start from what the model’s output will be used for. If a fixed threshold will turn scores into actions, report the confusion matrix at that threshold. Accuracy is enough when the classes are close to balanced and both errors cost about the same. Otherwise report precision and recall, and combine them with or . Before the threshold is fixed, compare candidate models with a ranking metric. ROC-AUC is the default, and its values carry over between sites with different prevalence. Switch to average precision when positives are rare. A small false positive rate then still produces more false alarms than true positives, and only precision shows it. Use log loss whenever the probability values matter. Pricing a risk and combining the model with costs later are two such cases. A ranking metric cannot detect a model whose 90% predictions come true 70% of the time.

The threshold itself depends on the costs. With calibrated probabilities and equal costs, a threshold of 0.5 maximizes the expected accuracy. Under class imbalance the threshold that maximizes is lower. Unequal costs move the threshold up or down, as 4.1. Bayes Classifier derives. A sound report gives one threshold-free metric for model selection and the confusion matrix at the deployed threshold. Every metric should come from held-out data split by the unit of deployment, as 2.3. Generalization explains.

Examples

(Easy) One Model, Five Numbers

A fraud model scores ten transactions. The three frauds get probabilities 0.9, 0.7 and 0.4. The seven legitimate transactions get 0.6, 0.3, 0.2, 0.2, 0.1, 0.1 and 0.05.

See Also