Metrics Fundamentals
One number that tells a story — if you pick the right one
A metric converts model behavior into a single number you can act on. Choosing the right metric matters more than most modeling work — it decides which model wins and what the business sees.
What you will learn
- Explain why metric choice changes which model gets shipped
- Match metric families to task type (regression, classification, ranking)
- Spot when a metric is being gamed and needs a sharper cousin
What is this?
A metric is a scalar function that scores how well a model's predictions match reality on a fixed dataset. Metrics distill hundreds of thousands of errors into one comparable number, but they also encode an assumption about what 'good' means — so the same model can rank first on one metric and last on another. Choosing the metric is a product decision, not a statistics footnote.
Why do you need it?
- Model A and B both 'work', but only a metric can say which one is better and by how much.
- Metrics expose failure modes you would miss visually — a 95% accuracy model can still be useless for rare diseases.
- The right metric aligns optimization with the business objective (money, safety, engagement).
- A poorly chosen metric silently optimizes the wrong thing for months.
Mental model
A thermometer vs a barometer
A metric vs a model
Neither instrument tells you everything; you pick the one that measures what you actually care about. Metrics are the same — you choose the instrument that matches the risk you are worried about, not the one that looks most impressive.
How it works
- You hold out data the model never trained on (validation/test) so the metric measures generalization, not memory.
- You compute an error between each prediction y_hat and true value y using a per-row error function.
- You aggregate per-row errors into a scalar — mean (sensitive to outliers), sum, median, or a ratio.
- You compare the scalar across models or against a baseline (majority class, mean predictor, previous version).
- You sanity-check the metric against a small sample you can verify by hand before trusting it at scale.
From predictions to a decision-making number.
In production
- The ads team ranks models by expected revenue lift — not accuracy — because a 0.5% accuracy gain that loses $2k/day is a loss.
- A lending model is gated on recall of default at a fixed threshold, so a metrics drift alert fires when that recall drops.
- A ranking team evaluates with nDCG@10 because users only see the top ten results.
Best practices
- Define the primary metric from the business objective before training begins.
- Report at least two metrics: the decision metric plus a diagnostic (e.g., accuracy + calibration).
- Track metrics on the same untouched test set across every experiment for apples-to-apples comparison.
- Log metric definitions with experiments — a metric that changes meaning is a metric that lies.
Common mistakes
- Letting the primary metric be whichever number looks best at review time.
- Skimming the average and ignoring where errors concentrate (segments, tails).
- Comparing models trained on different data/feature mixes as if the metric were comparable.
- Reporting test metrics computed after tuning on that set — an inflated, optimistic number.
Common issues
Accuracy says 98% but the product is failingClass imbalance — the model predicts the majority class and is rewarded
Use a metric that penalizes minority-class misses (recall, F1, PR-AUC) and inspect the confusion matrix.
Same model, two metrics, opposite winnersMetrics weight errors differently (RMSE punishes big errors, MAE treats all equally)
Choose the single metric whose error weighting matches your cost structure.
Validation metric is higher every day even though nothing changedMetric code or data pipeline changed without being logged
Hash the eval script + dataset version into every experiment record.
Debugging tips
- Recompute the metric on a 50-row sample by hand to catch sign and aggregation bugs.
- Plot the error distribution, not just the mean — a perfect RMSE can hide a bimodal disaster.
- If two metrics disagree, figure out which one is sensitive to the errors you actually care about.
- Log the exact version of the evaluation script; metric code changes silently invalidate history.
Interview checkpoint
Quick quiz
Which describes the main job of an evaluation metric?
A metric's assumptions should match the business cost of errors.