← All AI/ML articles

Classification metrics, visualised.

A classifier gives each item a score, and you choose where to draw the line. Slide that line and watch accuracy, precision, recall, F1 and ROC-AUC respond, and learn why one number is never enough.

1. Count the four outcomes2. Trade precision for recall3. Judge it with ROC-AUC
actual negativesactual positivesfaded bars = mistakes
Drag on the chart (or use the slider) to move the threshold. Items scoring at or above it are predicted positive.
Accuracy0
Precision0
Recall0
F10
ROC-AUC (same at any threshold)0
Majority-class baseline accuracy0
The two “best” buttons search 101 thresholds (0.00 to 1.00 in steps of 0.01) on the current data. If several thresholds tie, the lowest one wins.
Behind the scenes · 1

Everything starts from four counts

Every prediction is one of four outcomes: a true positive (TP), false positive (FP), false negative (FN) or true negative (TN). Each metric is just a different ratio of those four numbers, and each answers a different question. The table updates as you move the threshold.




What F1 leaves out. F1 ignores true negatives completely, and it treats a false positive and a false negative as equally costly. In real applications they rarely are (a missed tumour is not the same as a false alarm), so pick the metric, and the threshold, that matches your actual costs.

Behind the scenes · 2

The precision and recall tug-of-war

Lower the threshold and you catch more real positives (recall rises) but also raise more false alarms (precision usually falls). Raise it and the opposite happens. This is a tendency, not a strict rule: precision can wobble up or down from one threshold to the next, so look for bumps in the cyan line. F1 balances the two. Click the chart to try a threshold.


accuracyprecisionrecallF1
The white line marks your threshold and the star marks the threshold with the best F1. Where a line is missing, that metric is undefined (nothing was predicted positive).

Behind the scenes · 3

ROC curve and AUC: all thresholds at once

The ROC curve plots recall (true positive rate) against false positive rate for every possible threshold. The area under it, AUC, is the chance that a random positive scores higher than a random negative: 1.0 is perfect, and 0.5 is what random ranking gives on average. Switch to the precision-recall view to see how class imbalance changes the picture. Click a table row to move the threshold.


– means undefined: nothing was predicted positive at that threshold, so precision is 0 ÷ 0.

ROC-AUC summarizes how well a model ranks positive cases above negative cases across thresholds. It doesn’t depend on the selected threshold, but it doesn’t tell you which threshold is best for your application. When positives are rare, also examine the precision-recall curve and the cost of false positives and false negatives. A random-ranking classifier has an AUC of 0.5 in expectation; an individual model can score below 0.5.


Experiment

Break it on purpose

The accuracy trap

Only 5% positives and a strict threshold. Accuracy looks great, but the model catches almost none of them.

Chase recall

A very low threshold flags nearly everything. Recall hits the top and precision collapses.

Be picky

A very high threshold flags only sure things. Precision is high but many positives slip through.

Check yourself

Three quick questions


Key takeaways

  • Confusion matrix: TP, FP, FN and TN are the raw counts every metric is built from.
  • Accuracy can mislead when classes are imbalanced: always guessing the majority class can score very high.
  • Precision asks "when I say positive, am I right?" and recall asks "how many positives did I find?"
  • F1 is the harmonic mean of the two, so it is low unless both are reasonably high.
  • ROC-AUC scores the ranking across all thresholds. For rare positives, also look at precision-recall.
← Back to all articles