E ExamMaster

Machine Learning · Machine Learning Core

Evaluation Metrics

Accuracy, precision/recall and the train–test gap are how you judge classical predictors — the metric has to match the decision cost.

A model without a metric matched to the decision is a demo. This lesson locks when accuracy lies, the confusion-matrix vocabulary, how precision and recall trade off, and the train-versus-test signature of overfitting. ROC and AUC get their own lesson next.

  • Machine Learning
  • Medium level
  • 6 concepts
  • 10 practice questions

1Accuracy, the obvious first score

Picture a program a bank runs on every card payment. For each payment it makes a prediction — a guess about a label it cannot see yet — and here the label is one of two words: 'legit' (a normal purchase) or 'fraud' (a stolen card being used). Once the truth comes out, each guess is either correct (the model said what the payment really was) or wrong. The obvious question is: how good is this model? The first score everyone reaches for is called accuracy.

Accuracy is simply the number of correct predictions divided by the total number of predictions made. If the model looked at 100 payments and got 95 of them right, its accuracy is 95/100 = 0.95, which people read as 95%. Nothing hidden: right answers over all answers. It feels like the whole story — and that feeling is exactly the trap this concept exists to warn you about.

Figure. One hundred payment predictions laid end to end: 95 came out correct and 5 wrong, so accuracy is 95 out of 100 — read as 95%. Right answers over all answers, nothing hidden.

One shift of payments, scored by hand

The bank's fraud model worked one afternoon shift of 200 card payments. The truth is now known: 190 of them were legit and 10 were fraud. Checking the model's guesses against that truth, it correctly left alone 188 of the 190 legit payments (it wrongly flagged the other 2), and it correctly flagged 8 of the 10 frauds (the other 2 slipped past it). Accuracy is correct predictions divided by all predictions — so count the correct guesses on each kind of payment, add them, check nothing was dropped, and compute the shift's accuracy.

  • Correct guesses on the legit payments: the model left 188 of the 190 alone, and leaving a legit payment alone is a correct call188 correct
  • Correct guesses on the frauds: it flagged 8 of the 10, and flagging a real fraud is a correct call8 correct
  • Total correct, adding the two kinds together: 188 + 8196 correct predictions
  • Cross-check with the wrong guesses: 2 legit payments wrongly flagged plus 2 frauds missed is 2 + 2 = 4 wrong, and 196 + 4200 — every payment counted exactly once
  • Accuracy, correct over total: 196/2000.98, read as 98%
  • The error rate is the same coin flipped: 4/200 = 0.02, which is 1 - 0.980.02 — accuracy and error rate always sum to 1

Pro tip. Watch what the addition in the third row quietly did: a missed fraud and a wrongly-flagged legit payment each cost the model exactly one point, no more and no less. Accuracy pools every kind of correct into one pot and every kind of wrong into another, and whether that even-handed pricing is fair for a fraud desk is precisely the question the rest of this lesson forces.

A test set contains 990 healthy patients and 10 diseased patients. What is the accuracy of a model that diagnoses everyone as healthy?
  1. 10.0%, because only the minority class is evaluated
  2. 99.0%, despite failing to identify a single diseased individual
  3. 50.0%, representing random chance guessing
  4. 0.0%, because the classifier failed on the critical class

The model gets all 990 healthy patients right out of 1000 total: 990/1000 = 99%, masking its complete inability to detect disease.

2The do-nothing model scores 95%

Here is the trap. In real card traffic, fraud is rare: out of every 100 payments, maybe 95 are legit and only 5 are fraud. That 95-to-5 balance is called the base rate — how often each label actually occurs before any model gets involved. Now imagine the laziest possible model: it ignores the payment entirely and says 'legit' every single time. It is right on all 95 legit payments and wrong on all 5 frauds, so its accuracy is 95/100 = 0.95. A model that catches zero fraud — the one job it was built for — reports a shiny 95%.

Why does the number lie like this? Because accuracy counts every correct answer as equally valuable, so a model can rack up a huge score just by always guessing the majority class — the label that appears most often (here, 'legit'). The rare label we actually care about hunting — the fraud — is what evaluators call the positive class, and on skewed data accuracy barely notices whether the positives are found at all. The more lopsided the base rate, the higher a do-nothing model scores.

Figure. On a 95% / 5% split, a model that always calls the majority class scores 0.95 accuracy and finds zero rare positives. The tall bar is the trap; the empty bar is the cost. Quote the base rate before you quote accuracy.

Base rate vs do-nothing score
Base rateAlways-majority accuracyWhat it hides
Roughly 50 : 50 — cats vs dogs photos50/100 = 0.50 — no reward for guessing the majorityNothing — with balanced classes the trap disappears
95 legit : 5 fraud per 100 payments95/100 = 0.95 — looks excellentAll 5 frauds missed — the one job it was built for
1 fraud in 200 transactions199/200 = 0.995Catches no fraud whatsoever
One transaction in 200 is fraudulent. A model that never flags anything reports what accuracy, and what is it worth?
  1. 50%, and it is worth nothing
  2. 99.5%, and it is a fair baseline to put into production
  3. It cannot be worked out without seeing the confusion matrix
  4. 99.5%, and it is worth nothing, because it catches no fraud whatsoever

Accuracy rewards the majority class in proportion to how dominant it is. On a 1-in-200 problem the do-nothing model is 99.5% right and 0% useful.

3Base rate and cost beside the number

So before you quote accuracy, write two things next to it. First, the base rate: if a do-nothing majority guesser would already score 95%, then a model reporting 95% has told you nothing. Second, the cost of each kind of mistake: missing a real fraud loses the bank real money, while a false alarm merely means a customer gets a 'was this you?' text. When the mistakes cost different amounts, or the base rate is skewed, you need scores that look at the rare class directly — recall (of the real frauds, how many did we catch?) and precision (of the payments we flagged, how many were really fraud?). Those two get their own lesson next; for now just know they exist and why accuracy alone sent you looking for them.

None of this makes accuracy useless. When the classes are roughly balanced — say, sorting photos into cats and dogs, where both appear about half the time — and both kinds of mistake cost about the same, correct-over-total is a perfectly fair headline. The rule of thumb: balanced classes and equal costs, accuracy can lead; skewed either way, accuracy is only a sanity check, never the decision metric.

  1. Count the base rateBefore trusting accuracy, check how often each class appears — a majority vote can look brilliant.
  2. Match metric to costFraud and churn need precision/recall or ROC — not a single accuracy headline.
  3. Compare train vs testA wide gap signals overfit even when test accuracy still looks acceptable.
When accuracy misleads
SituationBetter focus
Rare positives (fraud, disease)Recall / PR / ROC-AUC
Asymmetric costsCost-weighted errors or threshold tune
Balanced, equal costsAccuracy can be the headline

The lower accuracy wins

Back in the fraud-screening world this lesson runs on — 1,000 card payments, 950 legit and 50 fraud — the bank is choosing between two models. Model A is the do-nothing guesser: it calls every payment 'legit' and never flags anything. Model B actually hunts: it catches 40 of the 50 real frauds, but along the way it wrongly flags 52 legit payments (52 false alarms). The bank has also priced its two kinds of mistake: a missed fraud costs $500 in stolen money, while a false alarm costs $5 — the price of a 'was this you?' text and a short hold on the card. Compute each model's accuracy, then each model's total mistake bill, and decide which model the bank should ship.

  • Base rate first: 950 of the 1,000 payments are legit, so a guesser that always says 'legit' already scores 950/10000.95 — the do-nothing baseline
  • Model A is exactly that guesser: right on all 950 legit payments, wrong on all 50 frauds, so its accuracy is 950/10000.95
  • Model B's correct answers: it leaves 950 - 52 = 898 legit payments correctly alone and catches 40 frauds, so 898 + 40938 correct out of 1,000
  • Model B's accuracy: 938/10000.938 — below Model A's 0.95
  • Model A's mistake bill: it misses all 50 frauds at $500 each and raises no false alarms, so 50 \times 500$25,000
  • Model B's mistake bill: it misses 50 - 40 = 10 frauds at $500 and raises 52 false alarms at $5, so 10 \times 500 + 52 \times 5 = 5000 + 260$5,260
  • Compare the two bills: 25000 - 5260$19,740 saved per 1,000 payments by shipping the lower-accuracy Model B

Pro tip. Accuracy ranked these two models backwards, because it charges every mistake the same one point while the bank's ledger charges a missed fraud one hundred times what it charges a false alarm. When the two mistakes cost different amounts, price the errors — do not just count them. And notice that Model A's 0.95 equals the base rate exactly: an accuracy that merely matches the do-nothing baseline has told you nothing about the model at all.

Why is a 95% accuracy figure impossible to judge without knowing the class base rate?
  1. If the majority class comprises 98% of the data, a 95% accuracy score is worse than a naive majority guess
  2. Accuracy cannot be mathematically computed unless classes are exactly 50/50
  3. High accuracy always implies perfect precision and recall regardless of base rate
  4. Base rates only matter when fitting unsupervised clustering algorithms

Without knowing the base rate, you cannot tell if 95% represents a breakthrough or an underperforming model that underperforms trivial constant guessing.

4Overfitting signals

Think of a student who prepares for an exam by memorising last year's answer key word for word. Quiz them on last year's paper and they score perfectly; hand them a fresh paper with new questions and they collapse, because they never learned the underlying method — only the specific answers. Machine-learning models can fail in exactly this way, and the failure has a name: overfitting.

To catch it, we split our data into two piles before any learning happens. The training set is the pile of rows the model is allowed to study — it sees both the inputs and the true labels and adjusts itself to fit them. The test set (also called the hold-out set, because we hold it out of reach) is a pile the model never sees during learning, locked away until the very end. The test set plays the role of the fresh exam paper: it measures whether the model learned patterns that generalise — that keep working on new data — rather than memorising the training rows.

Now score the same model on both piles. Suppose it gets 99% of the training rows right but only 71% of the test rows right. Neither number alone is the alarm — the 28-point gap between them is. A big gap with a glittering train score is the classic overfitting signature: the model latched onto quirks and coincidences that exist only in the training pile, exactly like the student who memorised one specific answer key.

Figure. The same model, two scores: 96% on rows it trained on, 71% on rows it has never seen. Neither number alone is the alarm - the 25-point gap is. Close it by simplifying the model, adding data, or regularising before reaching for anything exotic.

Grade the same model on both piles

The bank takes 1,000 past card payments whose true labels are already known and, before any learning happens, splits them: 700 payments go into the training set — the pile the model studies, inputs and true labels both — and 300 are locked away as the test set, which the model never sees while it learns. After training, the model's guesses are checked against the truth on each pile separately: it gets 693 of the 700 training payments right, and 213 of the 300 test payments right. Compute the score on each pile, the gap between them, and each pile's mistake rate, then read the numbers the way this concept says to.

  • Training-pile score, correct over total on the pile the model studied: 693/7000.99 — a glittering 99%
  • Test-pile score, the same division on the pile it never saw: 213/3000.71 — only 71%
  • The gap between the two scores: 0.99 - 0.710.28 — a 28-point gap
  • Mistakes on each pile, counted: training 700 - 693 = 7; test 300 - 213 = 877 mistakes versus 87
  • Mistake rate on each pile: 7/700 = 0.01 against 87/300 = 0.29, and 0.29/0.0129 — the model errs 29 times as often on payments it has never seen

Pro tip. The 99% is not evidence of skill — the model graded itself on answers it had already studied. Only the 71% estimates how it will do on genuinely new payments, and the 28-point distance between the two measures how much of the training score was memorisation. On its own, 71% indicts nothing: for a hard problem it might be a respectable score. The alarm is the gap.

A classifier achieves 99.8% accuracy on training data but only 64.2% on the test set. What is this discrepancy called?
  1. Underfitting, caused by insufficient model parameter capacity
  2. Overfitting, where the model has memorised training idiosyncrasies that do not generalise
  3. Class imbalance leakage during cross-validation
  4. Underflow in floating-point gradient updates

A large divergence between near-perfect training performance and mediocre test performance is the defining symptom of overfitting.

5Read the two scores together

Be careful not to confuse this with the opposite problem. If the train score and test score are both poor and close together — say 61% and 60% — the model is not memorising anything; it is too simple, or its input features are too weak, to capture the pattern at all. That is underfitting, and its remedy (make the model richer, or find better features) is the exact opposite of the overfitting remedy. Always read the two scores together: a wide gap says overfit, two low scores in agreement say underfit.

Train vs test reading
PatternLikely issue
Train ≫ testOverfitting / leakage
Train ≈ test, both lowUnderfitting / weak features
Train ≈ test, both highHealthy — still check base rates
A model scores 58% on training data and 57% on test data on a problem where human baseline is 92%. What does this indicate?
  1. Underfitting, meaning the model lacks the capacity or features to learn the underlying pattern
  2. Severe overfitting, because training score is higher than test score
  3. Data leakage between the train and test partitions
  4. Optimal convergence, because train and test scores match closely

When both train and test scores are low and close together, the model is underfitting: it has high bias and lacks expressiveness to capture the signal.

6Fixing an overfit model

So what do you actually do about an overfit model? Start by making it simpler, not fancier: a shallower decision tree means fewer, broader rules with less room to memorise individual rows, and stronger regularisation — a penalty added during training that punishes overly complicated fits — pushes the model toward smoother, simpler patterns. Adding more (and cleaner) training rows also helps, because quirks that appear in 800 rows tend to wash out across 8,000. And one rule is absolute: never tune your settings by re-running against the test set. Every time you adjust the model to raise the test score, the test set quietly turns into another practice paper the model has effectively seen — and it can no longer tell you how the model will do on genuinely new data. Keep a separate validation slice for tuning; touch the test set once, at the end.

Only after those basics are exhausted should anyone reach for a more exotic model. Extra complexity is not a cure for a wide gap — it usually widens it — and it certainly cannot fix data leakage, where an input column secretly contains the answer (imagine a 'refund issued' column leaking into a fraud predictor). If a score looks too good to be true, suspect the data before you celebrate the model.

  1. Simplify firstShallower trees and stronger regularisation leave less room to memorise individual rows.
  2. Add cleaner rowsQuirks that survive in 800 rows tend to wash out across 8,000.
  3. Guard the test setTune on a separate validation slice; touch the test set once, at the end.
What closes the gap — and what doesn't
MoveEffect on the gapWhy
Shallower tree, stronger regularisationNarrows itFewer, broader rules leave less room to memorise individual rows
More, cleaner training rowsNarrows itQuirks that survive in 800 rows wash out across 8,000
A fancier, more complex modelUsually widens itThe model has already learned more than the data supports
Tuning settings against the test setHides itThe test set becomes another practice paper and can no longer speak for new data
Any model change, when a column leaks the answerCannot fix itA 'refund issued' column feeding a fraud predictor — suspect the data before celebrating the model
Train accuracy is 0.99 and test accuracy is 0.71. Which move is least likely to help?
  1. Adding depth and width so the model has the capacity to fit the test set as well
  2. Collecting more training rows
  3. Turning the regularisation strength up
  4. Dropping features only weakly related to the target

The gap says the model has already learned more than the data supports. More capacity widens the gap, and nothing legitimate is ever fitted to the test set.

Notes

  • Accuracy, precision, recall and overfitting signals.
  • Accuracy is correct predictions divided by all predictions — simple, and often the wrong headline.
  • A binary classifier has four cells: true positives, false positives, true negatives, and false negatives.

Exam traps & shortcuts

  • Keep lab datasets under 2000 rows in the browser runtime.
  • Split train and test before fitting any model that sees labels.

Recap

This lesson in brief:

Accuracy and its trap
Accuracy is correct predictions divided by all predictions — simple, and often the wrong headline.
Confusion matrix vocabulary
A binary classifier has four cells: true positives, false positives, true negatives, and false negatives.
Precision and recall
Precision asks: of the rows I called positive, how many were right? High precision means few false alarms.
Overfitting signals
The classic signature is a train score much higher than the hold-out score — the model memorised quirks that do not generalise.

Practise Evaluation Metrics

Reading is free and needs no account. Practice, mocks and progress live in the app.

  • 10 exam-style questions on this topic, with explanations
  • A 5-question practice set that ends the chapter
  • Timed mocks scored with the real marking scheme
  • Readiness tracked per topic, kept on your device
Continue with Google — freeNo card, no trial. Works offline once installed.