Lesson 3 of 6 The ML Development Lifecycle and MLOps

Measuring Model Performance with Evaluation Metrics

This lesson explains how metrics measure how well a model performs, how to choose the metric that reflects the real cost of a mistake, and how to connect technical metrics to business value.

Learning outcomes

After completing this lesson, you will be able to:

  • Interpret a confusion matrix.
  • Distinguish accuracy, precision, recall, F1 score and AUC.
  • Choose a metric from the business cost of each kind of error.
  • Identify the metrics used for regression models and for business value.

The confusion matrix

A confusion matrix compares a classification model's predictions with what actually happened. A true positive (TP) is a positive case correctly flagged, such as a fraudulent transaction caught, and a true negative (TN) is a negative case correctly passed. A false negative (FN) is a positive case the model missed, such as fraud that got through, and a false positive (FP) is a false alarm, such as a genuine customer's payment blocked. The following table shows the four outcomes.

Predicted positivePredicted negative
Actually positiveTrue positive (TP)False negative (FN): a miss
Actually negativeFalse positive (FP): a false alarmTrue negative (TN)

Every classification metric is calculated from these four numbers.

The following diagram lays out the four outcomes and the two metrics built from them.

The confusion matrix. Rows are what actually happened and columns what the model predicted. A true positive is a positive case correctly flagged, a false negative a positive case missed, a false positive a false alarm and a true negative a negative case correctly passed. Precision is TP divided by all predicted positives, recall is TP divided by all actual positives, and every classification metric comes from these four numbers.
Choose the metric by which error costs more.
Match the pairs

Four outcomes

Exam skills 1.3.6

A spam filter treats spam as the positive class. Match each outcome with its name.

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

Classification metrics

Each classification metric answers a different question. Accuracy is the share of all predictions that were correct. It is misleading when one class is rare: if 1% of transactions are fraud, a model that always says "not fraud" is 99% accurate but useless. Precision asks, of everything the model flagged, how much was really positive; it matters when false alarms are costly. Recall, also called sensitivity, asks how many of the real positives the model found; it matters when misses are costly.

The F1 score combines precision and recall into one number, which is useful when classes are imbalanced. AUC-ROC measures how well the model separates the classes across every possible decision threshold, from 0.5 for random guessing to 1.0 for perfect. The following table summarises the metrics.

MetricFormula or meaningNote
AccuracyCorrect predictions ÷ all predictionsMisleading for imbalanced data: always saying "not fraud" is 99% accurate if 1% is fraud
PrecisionTP ÷ (TP + FP): how much of what was flagged was really positiveMaximise when false alarms are costly
Recall (sensitivity)TP ÷ (TP + FN): how many real positives were foundMaximise when misses are costly
F1 scoreHarmonic mean of precision and recallOne balanced number for imbalanced classes
AUC-ROCHow well the model separates classes across thresholds1.0 is perfect; 0.5 is guessing
Fill in the value

Screening metrics

Exam skills 1.3.6

A screening model checked 1,000 patients: 40 true positives, 10 false negatives, 60 false positives and 890 true negatives.

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

Choosing by the cost of errors

Which metric to optimise depends on which mistake costs the business more. When missing a positive is expensive, as in fraud detection, cancer screening or finding safety defects, the model should catch as many positives as possible, so it is tuned for recall, accepting more false alarms. When a false alarm is expensive, as when blocking a legitimate customer or deleting a real email as spam, the model should flag only cases it is sure of, so it is tuned for precision, accepting more misses. The following table summarises the choice.

When this is expensiveOptimise forExamples
Missing a positiveRecallFraud detection, cancer screening, safety defects
A false alarmPrecisionBlocking legitimate customers, deleting real email

Moving the decision threshold trades one for the other.

Sort into groups

Precision or recall?

Exam skills 1.3.6

Decide which metric each model should be tuned for, given the mistake that costs most.

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

Regression and business metrics

Regression models predict numbers, so they are judged by how far their predictions are from the true values. MAE (mean absolute error) is the average size of the errors, in the same units as the prediction, such as an average error of $12 on a price. RMSE (root mean squared error) squares the errors before averaging, so it penalises large errors more heavily, which matters when a few big mistakes are worse than many small ones. R² measures how much of the variation in the data the model explains, where values closer to 1 are better. The following table summarises the metrics.

MetricMeaning
MAE (mean absolute error)Average size of the errors
RMSE (root mean squared error)Penalises large errors more
R²How much of the variation the model explains; closer to 1 is better

Business metrics show whether a model is worth having: ROI, cost per user or prediction, development and running cost, revenue or conversion uplift, time saved and customer feedback. A slightly better F1 score is not worth much higher cost.

Scenario questions

Judging a regression model

Exam skills 1.3.6

Choose the metric for each situation.

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

Calculating metrics for a fraud model

A fraud model is tested on 10,000 transactions, of which 100 are really fraudulent. The results form a confusion matrix:

Predicted fraudPredicted genuine
Actually fraud (100)TP = 80FN = 20
Actually genuine (9,900)FP = 120TN = 9,780
Accuracy  = (TP + TN) / total          = (80 + 9,780) / 10,000   = 98.6%
Precision = TP / (TP + FP)             = 80 / (80 + 120)         = 40%
Recall    = TP / (TP + FN)             = 80 / (80 + 20)          = 80%
F1        = 2 x P x R / (P + R)        = 2 x 0.4 x 0.8 / 1.2     = 53%

Accuracy looks excellent, but a model that never flagged anything would score 99%, so accuracy says almost nothing here. Recall shows the model catches 80% of fraud; precision shows that only 40% of its alerts are real fraud, so investigators handle 120 false alarms. If missing fraud is the bigger cost, the bank may accept this; if investigators are overwhelmed, it raises the decision threshold, trading some recall for better precision.

Check yourself

Which metric matters most when missing a positive case is very costly, such as missing a disease?

Show answer

Recall, the share of actual positives the model finds. Precision matters more when false alarms are the costly mistake.

Exam Tips

Remember for the exam

  • With imbalanced classes, accuracy is misleading; use precision, recall, F1 or AUC instead.
  • When missing positives is costly, as with fraud or disease, optimise for recall.
  • When false alarms are costly, optimise for precision.
  • To balance precision and recall in a single number, use the F1 score.
  • Regression errors are measured with MAE, RMSE and R².
  • Business value is measured with ROI, cost per user and conversion.