Menu

Model Evaluation and Choosing Metrics

Lesson 4: Model Evaluation and Choosing Metrics

Why evaluation matters

  • A model must be evaluated on data it wasn't trained on.
  • Otherwise reported performance may reflect memorisation, not the ability to generalise.

Data split

Purpose

Training setFit the model
Validation setTune settings and compare models
Test setFinal, unbiased performance check, used once
Cross-validationRotate train/validation splits for more reliable estimates

Classification metrics

Confusion matrix:

 

Predicted positive

Predicted negative

Actual positiveTrue positive (TP)False negative (FN)
Actual negativeFalse positive (FP)True negative (TN)

Metric

Formula

Answers

Accuracy(TP + TN) ÷ totalHow often is the model right overall?
PrecisionTP ÷ (TP + FP)When it predicts positive, how often is it right?
Recall (sensitivity)TP ÷ (TP + FN)Of all actual positives, how many did it find?
F1 score2 × (Precision × Recall) ÷ (Precision + Recall)Balance of precision and recall
ROC-AUCArea under the ROC curveHow well does it rank positives above negatives across thresholds?
PR-AUCArea under the precision-recall curveUseful when positives are rare

Which metric matters?

Situation

Prioritise

Why

Fraud detectionRecallMissing fraud is costly
Spam filterPrecisionWrongly blocking real email is costly
Medical screeningRecallMissing a case is dangerous
Balanced costsF1 or accuracyBoth error types matter similarly

Regression metrics

Metric

Meaning

Notes

MAEAverage absolute errorEasy to explain
RMSERoot of mean squared errorPenalises large errors more
R²Share of variance explained vs a mean-only baselineHigh R² ≠ appropriate or causal model
MAPEAverage % errorUnstable near zero values

Example

Fraud detection with rare fraud:

Item

Value

Transactions10,000
Actual fraud50 (0.5%)
Model that predicts "legitimate" for everythingAccuracy = 99.5%
Recall for that model0% (finds no fraud)

High accuracy, useless model. This is why accuracy alone is misleading for imbalanced classes.

Common mistakes

  • Choosing metrics without considering business risk.
  • Ignoring class imbalance.
  • Using the default 0.5 threshold without testing alternatives.
  • Not reporting a baseline.
  • Looking only at one headline score instead of examining the errors themselves.
  • Re-using the test set to tune the model, which makes the final score over-optimistic.

Data Analytics Tutorial



Learn via Video Course

Data Analysis and Processing with Python using Pandas - Data Science Course Logo

Data Analysis and Processing with Python using Pandas - Data Science Course

5 hrs



Get in Touch For Details