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
| Metric | What it measures | Needs a threshold? | Range and chance level | Sensitive to class balance? | Default use |
|---|---|---|---|---|---|
| Accuracy | fraction of correct labels | yes | ; always predicting the majority class gives | yes, the majority class dominates | balanced classes, equal error costs |
| Precision, recall, $F_1$ | fraction of flags that are right; fraction of positives caught; their harmonic mean | yes | ; random flags give precision ; flagging everything gives | precision and yes, recall no | imbalanced classes at a fixed threshold |
| ROC-AUC | probability that a random positive outscores a random negative | no | ; | no | comparing rankings when the prevalence may shift |
| PR-AUC (average precision) | mean precision at the ranks of the positives | no | ; about | yes | rare positives, when the top of the ranking matters |
| Log loss | average negative log-probability of the true label | no, 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.
Compute each metric in the table and compare it with its chance level. , , and . Accuracy is 0.8, against 0.7 for always predicting "legitimate". Precision and recall are both , so . For ROC-AUC, the frauds at 0.9 and 0.7 outrank all seven legitimate transactions, and the fraud at 0.4 outranks six. The AUC is . In the ranking the labels read fraud, fraud, legitimate, fraud, and then legitimate to the end. Average precision is , against a baseline of 0.3. The log loss is 0.336, against for predicting 0.3 everywhere. Each metric clears its own baseline by a different margin. A metric reported without its baseline is therefore hard to read.
At threshold 0.5 the model flags 0.9, 0.7 and 0.6, so
See Also
- 2.2.1. Confusion Matrix, 2.2.2. ROC Curve, 2.2.3. Precision-Recall Curve and 2.2.4. Log Loss, the siblings.
- 2.1. Regression Metrics, the counterpart for real-valued targets.
- 2.3. Generalization, for how to split the data on which the metrics are computed.
- 4.1. Bayes Classifier, for the threshold that minimizes expected cost.