Choosing Classification and Regression Metrics
This lesson explains how evaluation metrics translate model behaviour into comparable numbers, and how the right metric depends on the problem type and which errors cost the business most.
Learning outcomes
After completing this lesson, you will be able to:
- Derive accuracy, precision, recall and F1 from a confusion matrix.
- Use ROC AUC and PR AUC as threshold-independent metrics.
- Choose between MAE, RMSE and R-squared for regression.
The confusion matrix and derived metrics
For binary classification, the confusion matrix counts true positives (TP), false positives (FP), true negatives (TN) and false negatives (FN). Accuracy is (TP + TN) / total and is misleading on imbalanced data. Precision is TP / (TP + FP): of the cases flagged positive, how many were right. Recall (sensitivity) is TP / (TP + FN): of the real positives, how many were found. F1 is the harmonic mean of precision and recall. Specificity is TN / (TN + FP).
Choose by the cost of errors: when missing a positive is expensive (fraud, disease), optimise recall; when a false alarm is expensive (blocking a legitimate payment, spam filtering important email), optimise precision; when both matter, use F1.
The following diagram shows the confusion matrix of a disease screening model tested on 10,000 patients, and the metrics derived from it.

Work out the metrics
Threshold-independent metrics
Most classifiers output a probability, and a threshold converts it into a class. The ROC curve plots the true positive rate against the false positive rate across thresholds, and ROC AUC summarises ranking quality (0.5 is random, 1.0 is perfect). On highly imbalanced data, the precision-recall curve and PR AUC are more informative because they ignore the large number of true negatives. After choosing a model by AUC, pick the threshold that meets the business target. Multiclass problems use per-class metrics with macro or weighted averages.
Choose the metric
Regression metrics
MAE (mean absolute error) is the average absolute difference and is easy to explain. MSE and RMSE square errors, so they penalise large errors more; RMSE is in the target's units. MAPE expresses error as a percentage but fails when actual values are near zero. R-squared is the share of variance explained. Forecasting also uses weighted quantile loss for probabilistic forecasts such as those from DeepAR. The following table summarises the metrics.
| Metric | Use when |
|---|---|
| Recall | Missing positives is costly (fraud, disease) |
| Precision | False alarms are costly |
| F1 | Balance of precision and recall |
| ROC AUC | Overall ranking quality, balanced data |
| PR AUC | Ranking quality on imbalanced data |
| MAE | Typical error size, robust to outliers |
| RMSE | Large errors are especially bad |
| R-squared | Share of variance explained |
Regression errors
A screening model
A disease screening model is evaluated on 10,000 patients, 200 of whom have the disease.
Predicted + Predicted -
Actual + TP = 170 FN = 30
Actual - FP = 490 TN = 9,310
Accuracy = (170 + 9,310) / 10,000 = 94.8%
Recall = 170 / 200 = 85%
Precision = 170 / (170 + 490) = 25.8%
F1 = 2 x 0.258 x 0.85 / (0.258 + 0.85) = 0.40For screening, missed cases are the worst error, so 85% recall matters more than 25.8% precision; positives go to a confirmatory test. Accuracy of 94.8% looks impressive but is below the 98% a model would score by predicting "healthy" for everyone, which shows why accuracy is the wrong metric here.
Which metric should be optimised when false alarms are costly?
Show answer
Precision.
Exam Tips
Remember for the exam
- Costly missed positives: optimise recall.
- Costly false alarms: optimise precision.
- Imbalanced data: PR AUC and F1 rather than accuracy.
- RMSE penalises large errors more than MAE.
- Choose the model by AUC, then set the threshold for the business target.