← Back to Curriculum
Training & Evaluation·30 min·Intermediate
🎯

Model Evaluation

Accuracy, precision, recall, F1, and ROC-AUC

Accuracy alone can lie. Here we learn the full scorecard—precision, recall, F1, confusion matrices, and ROC curves—so we can measure what truly matters.

Before We Begin

What we are learning today

Imagine a smoke detector that never goes off. Its "accuracy" on fire-free days is 100%, but it is completely useless. This lesson teaches students to see past the accuracy number and ask sharper questions: Of the alarms we raised, how many were real? (Precision.) Of all the real fires, how many did we catch? (Recall.) The F1 score balances both. The confusion matrix lays out every type of mistake in a neat grid, and the ROC-AUC curve shows how the model performs across all possible thresholds.

How this lesson fits

Building a model is one thing; training it well and knowing whether it actually works is another. This module covers the engine room of ML: how optimization drives learning, how bias and variance shape model behavior, how to pick the right scoreboard, and how to run experiments you can trust.

The big question

How do we train a model effectively, measure its true performance, and make sure our results are not just a fluke?

Trace a gradient descent step and explain how the learning rate controls itDiagnose overfitting vs. underfitting from training curvesChoose the right evaluation metric for a given problemDesign a fair experiment with baselines and reproducibility

Why You Should Care

In high-stakes domains—medicine, criminal justice, autonomous driving—the type of mistake matters as much as the rate. A model that misses 40% of cancers is dangerous even if its overall accuracy is 95%. Students must learn to choose metrics that match the real-world cost of errors.

Where this is used today

  • Cancer screening: maximizing recall so no tumor is missed
  • Spam filters: balancing precision (don't trash real email) with recall (catch most spam)
  • Credit scoring: using ROC-AUC to compare models across threshold choices

Think of it like this

Think of a spelling bee judge. Accuracy is "how many words did contestants spell correctly overall?" But that ignores the hard words. Precision asks "when the judge said correct, were they right?" Recall asks "of all the correctly spelled words, how many did the judge catch?" You need both lenses to know if the judging is fair.

Easy mistake to make

High accuracy does not mean a model is useful. On imbalanced data—where one class dominates—a model that always predicts the majority class can score high accuracy while being completely blind to the minority class.

By the end, you should be able to say:

  • Explain why accuracy can be misleading on imbalanced datasets
  • Define precision, recall, and F1 score and compute each from a confusion matrix
  • Read a confusion matrix and identify false positives vs. false negatives
  • Interpret an ROC curve and explain what AUC represents

Think about this first

A model predicts "no disease" for every patient and is 98% accurate. Is it a good model? Why or why not?

Words we will keep using

accuracyprecisionrecallF1 scoreconfusion matrixROC curveAUCthreshold

Accuracy Can Lie

A smoke detector that never goes off has 99% accuracy on fire-free days \u2014 and is completely useless. To measure what truly matters, we need sharper tools: precision, recall, F1, and the ROC curve.

# The four outcomes
TP = caught the real fire   FP = false alarm
FN = missed the fire    TN = correctly stayed quiet

Interactive: Confusion Matrix Explorer

Adjust the classification threshold. Watch how every cell changes. Lower the threshold to catch more positives (higher recall) at the cost of more false alarms (lower precision).

Accuracy: 73.5%
Precision: 56.1%
Recall: 73.0%
F1: 63.4%

Precision = TP / (TP + FP) \u2014 of all alarms, how many were real?

Recall = TP / (TP + FN) \u2014 of all real fires, how many did we catch?

F1 = 2 \u00d7 P \u00d7 R / (P + R) \u2014 the harmonic mean, balances both.

ROC Curve & AUC

The ROC curve traces every possible threshold. The area under it (AUC) summarizes model quality in a single number: 0.5 = random guessing, 1.0 = perfect. AUC is threshold-independent, making it ideal for comparing models.

When to use which metric
  • \u2022 Cancer screening: maximize recall (don't miss any tumor)
  • \u2022 Spam filter: balance precision (don't trash real email) with recall
  • \u2022 Credit scoring: use ROC-AUC to compare across thresholds
Imbalanced Data WarningIf 98% of samples are negative, a model that always says "no" gets 98% accuracy but 0% recall. Always check precision and recall, not just accuracy.

Key Formulas

Accuracy=TP+TNTP+FP+FN+TN\text{Accuracy} = \frac{TP + TN}{TP + FP + FN + TN}
Precision=TPTP+FP,Recall=TPTP+FN\text{Precision} = \frac{TP}{TP + FP}, \quad \text{Recall} = \frac{TP}{TP + FN}
F1=2PrecisionRecallPrecision+RecallF_1 = 2 \cdot \frac{\text{Precision} \cdot \text{Recall}}{\text{Precision} + \text{Recall}}
AUC=01TPR(FPR)d(FPR)\text{AUC} = \int_0^1 \text{TPR}(\text{FPR}) \, d(\text{FPR})