Lesson 1 of 6 Evaluating ML Models

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.

The screening model's confusion matrix on 10,000 patients, 200 of whom have the disease. Recall is 85% (170 of 200 found) and precision 25.8% (170 of 660 flagged). Accuracy of 94.8% looks good but is below the 98% that predicting healthy for everyone would score, so recall is the metric that matters for screening.
The scenario is illustrative.
Fill in the value

Work out the metrics

Exam skills 2.3.6

Calculate classification metrics from a confusion matrix.

Log in to try this activity Interactive activities are free with an account.

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.

Scenario questions

Choose the metric

Exam skills 2.3.6

Choose the metric that matches each business requirement.

Log in to try this activity Interactive activities are free with an account.

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.

MetricUse when
RecallMissing positives is costly (fraud, disease)
PrecisionFalse alarms are costly
F1Balance of precision and recall
ROC AUCOverall ranking quality, balanced data
PR AUCRanking quality on imbalanced data
MAETypical error size, robust to outliers
RMSELarge errors are especially bad
R-squaredShare of variance explained
Fill in the value

Regression errors

Exam skills 2.3.6

Calculate regression error metrics for three predictions.

Log in to try this activity Interactive activities are free with an account.
Worked example

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.40

For 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.

Check yourself

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.