Concept guide

Evaluation metrics for AI models

To answer "Is this model any good?" you need numbers. But pick the wrong number and a useless model can look great. This guide walks you through it step by step: precision and recall for classification models, errors for regression models, ways to score what a generative AI writes, and how to evaluate a model once real users are on it.

01

What goes wrong when you only look at accuracy

A card company builds a model to spot fraudulent transactions. They test it and get 95% accuracy. That means it got 95 out of 100 right, which sounds pretty good. But what if only 5 of those 100 transactions were fraud in the first place?

In the scene below, each cell is one transaction, and the red cells are the real fraud cases. Any cell the model flags as "fraud" pops forward. Switch between the two models.

Model
Accuracy
95%
Recall
0%

A model that picks out 5 fraud cases from 100 transactions

It did nothing and answered "normal" every time, yet accuracy is 95%. It caught zero fraud cases (recall 0%).

The model that always answers "normal" hasn't learned a thing, yet its accuracy is 95%. It didn't catch a single fraud case. The model that was actually trained has lower accuracy, 93%, but it caught 4 of the 5 fraud cases. The second model is the one this company needs.

Accuracy is the share of all predictions that were right. When one outcome vastly outnumbers the other — what's called imbalanced data — you can get high accuracy just by always guessing the common outcome. Most problems where the thing you're looking for is rare work like this: fraud detection, disease diagnosis, defect inspection.

"High accuracy means a good model" is wrong when the data is imbalanced. If an exam question mentions a lopsided split, like "only 1% of items are defective", that's your cue to pick a metric other than accuracy.

If a question says… → pick this

  • “Only 1% of the data is positive”Precision, recall or F1 instead of accuracy
  • “Always guessing the majority class still scores high”The accuracy trap

So what should you look at instead? It starts with sorting the model's hits and misses into four groups.

02

Confusion matrix, precision, recall and F1

When a model picks one of two answers, like "spam or not spam", every result lands in one of four boxes. The class you're trying to find (spam) is called positive, and the other one (normal email) is called negative. Then you put true in front if the model was right, and false if it was wrong.

Here's the part that trips people up. Say the model calls a normal email spam. It said "positive" and was wrong, so that's a false positive (FP). If it lets a spam email through as normal, that's a false negative (FN). The second word is what the model said; the first word tells you whether it was right.

Model says: spam (positive)Model says: normal (negative)
Actually spamTP — true positive: caught itFN — false negative: missed it
Actually normalFP — false positive: wrongly flaggedTN — true negative: correctly let through

This table is called a confusion matrix. From it, you get two key ratios.

Precision = TP ÷ (TP + FP)

Of everything the model called spam, how much really was spam? "When it flags something, is it right?" Look at this when wrong flags are costly.

Recall = TP ÷ (TP + FN)

Of all the real spam, how much did the model catch? "Did it catch everything?" Look at this when misses are costly. Recall is also called sensitivity.

A classification model usually gives a score between 0 and 1, and calls something positive if the score is above a threshold you choose. The scene below lines up 20 emails by score. Try moving the threshold.

Threshold
Confusion matrix
TP 4 · FP 3 · FN 2 · TN 11
Metrics
Precision 57% · Recall 67% · F1 62%

20 emails, 6 of them spam. Everything right of the threshold (raised cells) gets filtered as spam

Threshold 0.5: it caught 4 of the 6 spam emails (recall 67%), and 4 of the 7 emails it filtered are really spam (precision 57%). The lower the threshold, the higher recall goes and the lower precision goes.

Raise the threshold and the model only flags what it's sure about, so precision goes up — but more spam slips through, so recall goes down. Lower the threshold and the opposite happens. Usually, pushing one up pulls the other down. So you set the threshold based on which mistake costs more. For something like cancer screening, where missing a case is unacceptable, you favor recall. For a spam filter that must never bury an important email, you favor precision.

The F1 score lets you look at both at once. It's the harmonic mean of precision and recall, so if one is high and the other is low, F1 comes out low too. It's a common way to compare models with a single number on imbalanced data.

If a question says… → pick this

  • “Missing a case is unacceptable (disease, fraud)”Recall
  • “Wrongly flagging is unacceptable (spam filter)”Precision
  • “Precision and recall combined in one number”F1 score
  • “A negative wrongly predicted as positive”False positive (FP)
  • “A positive missed and predicted as negative”False negative (FN)

But if precision and recall change with every threshold, how do you compare two models before you've picked a threshold?

Advertisement

03

ROC curve and AUC

Lower the threshold bit by bit from 1 to 0, and at each step measure two things. The true positive rate (TPR) is the share of real spam you caught. The false positive rate (FPR) is the share of normal emails you wrongly filtered. TPR is the same thing as recall from chapter 2. Plot FPR across and TPR up, join the dots, and you get the ROC curve.

A good model catches spam quickly while only filtering a few normal emails by mistake, so its curve shoots up toward the top-left. A model that guesses at random follows the diagonal. The area under the curve is called the AUC (area under the curve). In the scene below, the area filled by the columns is the AUC.

Model
AUC
0.84

(FPR, TPR) plotted as the threshold moves from 1 down to 0. The area the columns fill is the AUC

It catches spam fast while only filtering a few normal emails by mistake. The more the curve hugs the top-left corner, the closer the area (AUC 0.84) gets to 1.

AUC runs from 0.5 (random guessing) to 1 (perfect). It sums up, in one number, how well the model separates positives from negatives without committing to a single threshold. That makes it handy for comparing several models before you've chosen a threshold. When you actually put a model into service, though, you still have to pick one threshold, and then you're back to precision and recall from chapter 2.

The vertical axis, TPR, is the same as recall (sensitivity). The horizontal axis, FPR, is 1 minus specificity (specificity is the share of negatives correctly identified as negative). If an exam describes "a curve plotting sensitivity against 1 − specificity", it's talking about the ROC curve.

If a question says… → pick this

  • “Compare models regardless of the threshold”AUC
  • “A curve of sensitivity against 1 − specificity”ROC curve
  • “AUC of 0.5”No better than random guessing

So far the models have been guessing a category, like "spam or not". A model that predicts a number, like sales or a house price, can't simply be right or wrong. You need to measure how far off it was.

Pro only

That’s the free part of this guide

The other 5 chapters are open to Pro subscribers. Each one continues with 3D visuals and “if a question says…” tips, and the last chapter lets you check yourself with a short quiz.

  1. 04MAE and RMSE
  2. 05Evaluating generated text
  3. 06LLM-as-a-judge and human evaluation
  4. 07A/B tests and business metrics
  5. 08Choosing a metric

PasslyExam

You have read the concept. Now test it on exam questions

PasslyExam offers original practice questions, explanations and full mock exams built around each certification’s exam guide. The explanations cover why the right option is right and why the look-alike options are wrong. Sign up to practice for free every day.