Skip to content
System AI
Open menu

How to Evaluate a Machine Learning Model

A practical guide to precision, recall, F1, ROC-AUC, and calibration, and how to choose evaluation metrics that reflect what mistakes actually cost.

By Editorial TeamPublished 8 min read
train station departures

A model is only as useful as the decisions it improves, and you cannot judge that from a single accuracy number. Two models with identical accuracy can have very different consequences: one misses most fraud cases while the other annoys thousands of legitimate customers. Choosing how to measure a model is a product decision as much as a technical one.

This guide covers the core metrics for classification models, explains what each one hides, and shows how to connect evaluation to the actual cost of mistakes.

Start with the confusion matrix

Most classification metrics come from four counts. For a binary task, say "is this transaction fraudulent?", every prediction falls into one of four buckets:

  • True positive (TP): predicted fraud, and it was fraud.
  • False positive (FP): predicted fraud, but it was legitimate.
  • True negative (TN): predicted legitimate, and it was legitimate.
  • False negative (FN): predicted legitimate, but it was fraud.

Laid out as a grid of predicted versus actual outcomes, these counts form the confusion matrix. Before looking at any summary metric, look at this matrix. It tells you what kind of mistakes the model makes, which is usually more important than how many.

Why accuracy misleads

Accuracy is the share of predictions that are correct: (TP + TN) divided by all predictions. It is intuitive and often useless.

Imagine a dataset where 1 transaction in 200 is fraudulent. A model that labels everything "legitimate" is correct 199 times out of 200. Its accuracy looks excellent, and it catches zero fraud.

Accuracy breaks down whenever classes are imbalanced, which describes most interesting problems: fraud, disease, churn, defects, security incidents. It also treats every error as equally bad, which is rarely true.

Precision and recall

These two metrics focus on the positive class, the thing you are trying to find.

Precision

Precision = TP / (TP + FP)

Of everything the model flagged, how much was actually positive? High precision means few false alarms. If a fraud model has high precision, when it blocks a transaction, it is usually right.

Recall

Recall = TP / (TP + FN)

Of all the actual positives, how many did the model catch? Recall is also called sensitivity or the true positive rate. High recall means few misses.

The trade-off

Most classifiers output a score, and you choose a threshold above which you call something positive. Lower the threshold and you flag more items: recall rises, and precision usually falls. Raise it and the reverse happens.

Neither metric is enough alone. A model that flags everything has perfect recall. A model that flags only its single most confident case may have perfect precision. Both are useless.

Which one matters more?

It depends on the relative cost of the two error types:

  • Favor recall when missing a positive is expensive: screening for a serious condition, detecting security breaches, flagging safety defects. A human can review false alarms.
  • Favor precision when false alarms are expensive or erode trust: automatically suspending user accounts, sending alerts that interrupt people, blocking payments without review.

F1 and its relatives

The F1 score combines precision and recall into one number using the harmonic mean:

F1 = 2 × (precision × recall) / (precision + recall)

The harmonic mean punishes imbalance. A model with precision of 0.9 and recall of 0.1 gets an F1 far closer to 0.1 than to the simple average of 0.5.

F1 is handy when you need one number to compare models and care about both error types. Its limitations:

  • It weights precision and recall equally, which rarely matches business reality.
  • It ignores true negatives entirely.
  • It is computed at one threshold, so it says nothing about behavior at other thresholds.

The F-beta score generalizes F1 with a parameter that shifts the weight. F2 weights recall more heavily; F0.5 weights precision more heavily. If you already know misses are worse than false alarms, F2 is a more honest summary than F1.

Multi-class averaging

With more than two classes, you compute precision and recall per class and then average:

  • Macro averaging treats every class equally, so rare classes count as much as common ones.
  • Weighted averaging weights classes by how often they occur.
  • Micro averaging pools all predictions together before computing the metric.

If performance on rare classes matters, report macro averages, and look at per-class numbers directly.

Threshold-independent metrics

Precision, recall, and F1 depend on a threshold. Sometimes you want to judge how well a model ranks examples before choosing one.

ROC curve and ROC-AUC

The ROC curve plots the true positive rate (recall) against the false positive rate, FP / (FP + TN), across every possible threshold. A model that ranks perfectly hugs the top-left corner. A model that guesses randomly follows the diagonal.

ROC-AUC is the area under that curve, from 0.5 for random ranking to 1.0 for perfect ranking. It has a clean interpretation: the probability that a randomly chosen positive gets a higher score than a randomly chosen negative.

ROC-AUC is useful for comparing ranking quality across models. Its blind spot is heavy class imbalance. The false positive rate divides by the number of negatives, and when negatives vastly outnumber positives, even a large absolute number of false alarms produces a small false positive rate. The curve can look impressive while, in practice, most flagged items are false alarms.

Precision-recall curve and average precision

The precision-recall curve plots precision against recall across thresholds. Average precision (or PR-AUC) summarizes it. Because it does not use true negatives, it reflects performance on the rare positive class much more directly.

For imbalanced problems, look at the PR curve. A random classifier's precision equals the positive rate in the data, so the baseline for a rare-event problem is very low, and improvements are easier to see.

Metric Answers Watch out for
Accuracy How often is the model right overall? Meaningless under class imbalance
Precision When it flags something, how often is it right? Can be high while missing most positives
Recall How many real positives does it catch? Can be high with floods of false alarms
F1 / F-beta Balance of precision and recall at one threshold Ignores true negatives; weights may not match costs
ROC-AUC How well does it rank positives above negatives? Overly optimistic when negatives dominate
PR-AUC How well does it find rare positives across thresholds? Harder to compare across datasets with different positive rates

Calibration: can you trust the scores?

Ranking metrics tell you whether higher scores mean more likely positive. Calibration asks a different question: when the model says 0.7, is the event actually true about 70 percent of the time?

Calibration matters whenever the score itself drives a decision:

  • Computing expected cost or expected revenue from a probability
  • Setting prices or credit limits based on risk
  • Showing confidence to users or reviewers
  • Combining the outputs of several models

A model can rank well and still be badly calibrated. Some model types tend toward overconfidence, pushing scores toward 0 and 1. Training on artificially rebalanced data also distorts probabilities.

How to check it

A reliability diagram groups predictions into bins by score, then plots the average predicted score against the observed positive rate in each bin. A well-calibrated model sits close to the diagonal. Summary numbers such as the Brier score, the average squared difference between predicted probability and actual outcome, capture calibration and sharpness together.

How to fix it

Fit a small calibration step on held-out data. Platt scaling fits a logistic curve to the scores. Isotonic regression fits a flexible, non-decreasing mapping and needs more data. Neither changes the ranking much; both make the numbers more trustworthy.

Choosing metrics that match business cost

The right metric starts from what errors cost, not from what is conventional.

Step 1: Describe the decision

What action follows a positive prediction? Blocking a payment, routing a ticket to a specialist, calling a customer, sending an item for manual review? The action determines what a false positive costs.

Step 2: Put rough numbers on each outcome

Imagine a subscription business deciding whom to offer a retention discount.

  • A true positive keeps a customer who would have left, preserving future revenue minus the discount.
  • A false positive gives a discount to someone who would have stayed anyway, losing the discount amount.
  • A false negative loses a customer the business might have saved.
  • A true negative costs nothing.

Even rough estimates are enough to show whether misses or false alarms dominate.

Step 3: Choose the threshold by expected value

With per-outcome values in hand, compute the total expected value at each threshold on validation data and choose the best one. This often lands somewhere very different from the default of 0.5.

value(t) = TP(t) * gain_tp - FP(t) * cost_fp - FN(t) * cost_fn
choose t that maximizes value(t)

Step 4: Respect capacity constraints

Many systems have a fixed budget of actions: a review team that can check a certain number of cases per day, or a sales team with limited calls. In those cases, measure precision at k: of the top k items the model ranks, how many are real positives? This aligns evaluation directly with how the model will be used.

Step 5: Add guardrail metrics

Pick one primary metric to optimize and a few guardrails that must not get worse, such as recall on a high-risk segment, performance for new users, or latency.

Evaluation hygiene

Good metrics on a flawed evaluation setup are still misleading.

  • Test on data that resembles production. If the model will score next month's traffic, validate on a later time period than training.
  • Slice the results. Overall numbers hide failures on specific segments: regions, device types, customer tiers, languages. Check each important slice.
  • Report uncertainty. With few positives, metrics swing a lot between samples. Bootstrap confidence intervals show whether a difference between models is real.
  • Compare against baselines. A simple rule or a basic model tells you whether complexity is earning its keep.
  • Keep a final test set untouched until you have made your choices.
  • Monitor after launch. Data and behavior change, and so does performance. Labels often arrive late, so plan how you will measure live results.

Key takeaways

  • Start with the confusion matrix; the type of mistake matters more than the count of mistakes.
  • Accuracy is misleading for imbalanced problems; precision and recall describe the positive class directly and trade off against each other through the threshold.
  • ROC-AUC measures ranking quality but can look optimistic when negatives dominate; precision-recall curves are more informative for rare events.
  • Calibration determines whether scores can be treated as probabilities, which matters whenever scores feed cost calculations or user-facing confidence.
  • Choose thresholds and metrics from the estimated cost of each outcome and from real capacity limits, not from default conventions.
  • Evaluate on production-like data, check important segments separately, and report uncertainty before declaring one model better than another.