07 - classification metrics
simple metrics
- suppose a model is predicting detector-failure for 1000 detector observations, wherein only 50 actually correspond to failures
| actually failure | actually normal | |
|---|---|---|
| predicted failure | 40 | 90 |
| predicted normal | 10 | 860 |
- here true positive,
, and true negative, , whereas false positive, , and false negative,
- accuracy is the fraction of all predictions that were correct:
- in the above examply, it is
- it is hiding the important fact that there were 90 false alarms, and 10 missed real failures
- recall measures how many of the actual positives were detected:
- here, it is
- it is also called sensitivity or true positive rate (TPR)
- precision is how often the model's predicted positive is actually positive:
-
here, it is
-
consider an airport security system that flags almost all items, so it has
recall but terrible precision -
on the other hand, it may flag only items it is extremely confident about, so the precision will be excellent, while the recall suffers
- specificity measures how many of the actual negatives were correctly identified:
- here, it is
- it is also called the true negative rate (TNR)
- the false positive rate (FPR):
- now consider a dataset with
normal measurements, but the model predicts everything as normal - here, the accuracy will be
, but , hence recall - so, accuracy can be almost useless for highly imbalanced classifications
F1 score
- the F1 score is the harmonic mean of precision and recall that balances these two scores:
- note how TN does not directly appear in F1, which is useful when the negative class is extremely common
- here,
- the harmonic mean heavily penalises imbalance, hence that is used
thresholds
-
a classifier often returns a probability, eg.
, rather than a classification, so a threshold must be chosen -
eg:
failure, normal -
if the threshold is lowered, more positives are retuned, increasing recall but decreasing precision
-
the converse is also true, giving the precision-recall tradeoff
-
which metric to prioritise is a domain question
-
if missing a positive is catastrophic, prioritise recall
-
if false alarms are more costly, prioritise precision
ROC curve

image: Evidently AI
-
by varying the classification threshold from 0 to 1, recall/TPR and FPR are calculated at each threshold, and TPR is plotted against FPR
-
a perfect classifier will be a straight line from
-
the area under the ROC curve (ROC AUC) summarises the ROC curve
-
excellent discrimination, random-level distribution -
values below
imply worse than random ranking
precision-recall curve
- a precision-recall curve can be more informative for highly imbalanced problems
- it focuses directly on performance for the positive/minority class
multiclass classification
- metrics can be approached using one-vs-rest reasoning
- they can then be aggregated using:
- macro averaging
- micro averaging
- weighted averaging
