Evaluation Metrics

Evaluation metrics are loss or scoring functions used after fitting to estimate usefulness. The metric must match the prediction type and decision cost: RMSE belongs to regression, precision and recall to classification, and Brier/log loss to probability quality and calibration.

Defining math

Regression metrics

For regression, let be the observed target, the prediction, and the number of evaluated examples:

MSE is the mean squared error: average squared prediction error. RMSE is the root mean squared error: the square root of MSE, bringing the score back to target units. MAE is the mean absolute error: average absolute prediction error, also in target units and usually less sensitive to outliers than RMSE.

Classification metrics

For binary classification, , , , and count true positives, true negatives, false positives, and false negatives at a chosen threshold:

Accuracy is the fraction of all examples classified correctly. Precision is the fraction of predicted positives that are actually positive. Recall is the fraction of actual positives recovered by the model; it is also called sensitivity or true positive rate in some domains.

Specificity, also called the true negative rate, measures how many actual negatives are correctly rejected:

Sensitivity is the positive-class recall. Specificity is the negative-class recall. They should be reported together when false negatives and false positives have different costs, such as medical screening, fraud review, abuse detection, or safety filters.

The same precision and recall terms also appear in ranked retrieval, where they measure the cleanliness and coverage of a result list rather than a classifier threshold. See Precision, Recall, MAP, MRR, and NDCG for the retrieval-side definitions.

The score is the harmonic mean of precision and recall :

For classes, let , , and be the one-vs-rest counts for class . Micro averages pool counts before computing the metric, while macro averages compute a per-class metric first:

Recall and use the same micro-versus-macro idea with their own per-class formulas.

Probability and ranking metrics

For probabilistic binary classifiers, let and let be the predicted probability of the positive class. Log loss is

Log loss, also called binary cross-entropy in many machine-learning contexts, rewards assigning high probability to the true label and punishes confident wrong probabilities strongly.

ROC-AUC summarizes how well positive examples are ranked above negative examples across all possible score thresholds:

Here is the model score, is a randomly chosen positive example, and is a randomly chosen negative example. This probability form is the same idea as the Mann-Whitney statistic, also called the Wilcoxon rank-sum statistic after a change of scale: AUC counts concordant positive-negative pairs, gives tied pairs half credit, and divides by the number of positive-negative pairs.

Average precision summarizes the precision-recall curve and is often reported as PR-AUC for rare-positive ranking tasks. Unlike ROC-AUC, precision-recall curves are strongly affected by the positive-class prevalence, which is why they are often more revealing under class imbalance.

Intuition

A metric is a compression of many errors into one number. Compression is useful only when the number preserves what the decision maker cares about. In classification, the starting point is usually the confusion matrix: examples can be actually positive or negative, and the model can predict positive or negative.

Thresholded metrics answer a decision question: after choosing a threshold, how many cases went into each cell of the confusion matrix? Accuracy measures the share of all decisions that were correct. Precision asks, “When the model predicted positive, how often was it right?” Recall asks, “Of all actual positives, how many did the model catch?” Raising the threshold often increases precision and decreases recall; lowering it often does the opposite.

Accuracy, precision, and recall as regions of actual positives, predicted positives, and their overlap.

Accuracy can be a poor summary when classes are imbalanced. If only 1% of transactions are fraudulent, a model that predicts “not fraud” for every case reaches 99% accuracy while detecting none of the fraud. Precision and recall force the report to say which positive-class errors are happening: false alarms, missed positives, or both. This is why class imbalance changes metric choice rather than merely changing the dataset description.

For multi-class classification, the same ideas can be averaged in different ways. A micro average first pools all per-class , , and counts and then computes the metric; large classes therefore dominate the result. A macro average computes the metric separately for each class and then takes the unweighted mean; rare classes therefore count equally with frequent classes. Weighted macro averages sit between those extremes by weighting each class metric by its support.

ROC-AUC answers a different question. It ignores any one threshold and evaluates the score ranking. To draw the ROC curve, sort examples by score and lower the threshold through that ranked list. When the next example is positive, the curve steps upward because the true positive rate increases. When the next example is negative, the curve steps right because the false positive rate increases. If every positive has a higher score than every negative, AUC is . If positives and negatives are randomly interleaved, AUC is near . A strictly increasing transformation of the scores changes calibration and threshold positions, but not AUC, because it preserves the order.

The pair-count view is often the clearest intuition. With positives and negatives, there are positive-negative pairs. A concordant pair has ; a discordant pair has the negative ranked above the positive. Discordant pairs are rank inversions: the adjacent swaps needed to move all positives above all negatives would count these misordered positive-negative pairs. AUC is high when few such inversions exist.

Worked example

Suppose a binary classifier produces these positive-class scores:

sampleactual labelscore
A00.05
B00.20
C00.35
D00.60
E10.40
F10.55
G10.80
H10.95

At threshold , only G and H are predicted positive. The confusion matrix is , , , and . Therefore

The thresholded metrics say that this operating point is conservative: every positive prediction is correct, but half of the actual positives are missed.

Accuracy, precision, and recall are computed from a thresholded confusion matrix.

ROC-AUC uses the same scores without fixing a threshold. First sort the examples by predicted positive-class score in descending order. In this example, that score permutation is H+, G+, D-, F+, E+, C-, B-, A-.

The curve moves upward for H and G, moves right for D, moves upward for F and E, then moves right for the remaining negatives. The plot labels each step with the sample that crosses the moving threshold. Because the ROC x-axis is false-positive rate rather than threshold, threshold crossings are shown as step labels rather than as a separate threshold axis. A positive that appears before a negative creates correctly ordered area; a negative that appears before later positives creates rank inversions.

There are four positives and four negatives, so there are positive-negative pairs. Two pairs are misordered because negative sample D with score ranks above positive samples E and F. The other 14 pairs are correctly ordered, so

ROC-AUC as area under a threshold curve and as concordant positive-negative pair ordering.

This explains why AUC can be high even when recall at one chosen threshold is low: the ranking is mostly good, but the chosen threshold is too strict for catching all positives.

Caveats

Do not tune on the test metric repeatedly and still call it an unbiased test estimate. Confidence intervals matter when model differences are small. Always pair aggregate metrics with slice checks when errors have unequal operational cost.

Accuracy is often misleading when the majority class dominates. Precision can be improved by making fewer positive predictions, even if recall becomes poor. Recall can be improved by predicting positive more often, even if precision collapses. ROC-AUC can look stable under severe class imbalance because the false-positive rate divides by all negatives; for rare-positive retrieval, average precision or the full precision-recall curve is usually more diagnostic.

Log loss and Brier score evaluate probabilities rather than hard labels. A model can have a good AUC and poor log loss when it ranks cases well but assigns badly calibrated probabilities; see calibration.

References