COMP328 Fundamentals of Machine Learning

Module 2 · Unit 6

Supervised Learning Model Evaluation

A model that scores 97% accuracy can be worse than useless. This unit is about the difference between a number that looks good and a model that is actually useful — measuring the right thing, on the right data, and reporting it honestly.

8 tutorials ≈4.5 hours guided study 1 quiz Module 2 capstone checkpoint

01 Why this unit

Everything you have built so far — a fitted regression, a trained classifier — is only as good as the evidence you bring to judge it. This unit teaches you how to gather that evidence properly, and how to tell when a model that looks impressive is quietly failing.

The central lesson is uncomfortable: a single number is almost never a sufficient evaluation. Accuracy hides class imbalance. Precision hides missed positives. ROC-AUC hides poor performance in the operating region you actually care about. A test score computed on data the model has already seen hides everything. Evaluation is therefore not a final step you perform once the modelling is done — it is a discipline that shapes how you split your data, how you tune your model, and how you decide when to stop.

What makes this unit different

  • It is about judgement, not computation. Almost every metric here is one line of scikit-learn. Knowing which line to run is the hard part.
  • It closes the loop on Modules 1–2. Every claim you made about a model in Units 4 and 5 has to survive the scrutiny introduced here.
  • It is where leakage is caught. Most of the catastrophic modelling errors in practice are evaluation errors, not algorithm errors.
  • It is directly transferable. The bias–variance framing and cross-validation discipline apply to every model in the rest of the course, including neural networks.
An ROC curve with the area under it shaded A receiver operating characteristic curve plotted with false positive rate on the horizontal axis and true positive rate on the vertical axis. The curve rises steeply toward the top-left corner, and the area beneath it is shaded to represent AUC. A dashed diagonal line represents a random classifier. False positive rate True positive rate 1.0 0.0
Figure 1. An ROC curve. The diagonal is a classifier that guesses at random; the closer the curve hugs the top-left corner, the better. The shaded region is the area under the curve (AUC). The marked point is one specific threshold — the curve itself is the model's behaviour across all thresholds at once.

How to study this unit

Every tutorial in this unit ends with a small dataset and a question of the form "which model is better?" Resist the urge to answer with a single number. Write down what a mistake would cost, then choose the metric. If you can do that consistently, you have the unit.

02 Learning outcomes

By the end of Unit 6 you should be able to do everything listed below without referring back to the notes. These outcomes are the ones the quiz and Assignment 3 are written against, and they carry forward into the capstone.

Knowledge

  • Explain why accuracy is misleading on imbalanced data, using a concrete numerical example.
  • Define precision, recall, specificity and the F1-score in terms of the four cells of a confusion matrix.
  • Describe what an ROC curve plots and what AUC summarises, and state the limitations of AUC on highly imbalanced problems.
  • Explain the purpose of cross-validation and why a single train/test split can be misleading.
  • State the bias–variance tradeoff and relate it to underfitting, overfitting and model complexity.

Skills

  • Construct and read a confusion matrix for a binary classifier.
  • Compute precision, recall, F1 and AUC with scikit-learn and interpret each in context.
  • Plot ROC and precision–recall curves and identify the operating point that matches a stated cost structure.
  • Run k-fold cross-validation correctly, including preprocessing inside the fold.
  • Diagnose underfitting and overfitting from learning curves and validation curves.
  • Detect data leakage in an evaluation pipeline and repair it.

Professional competencies

  • Choose an evaluation metric by reasoning about the cost of each error type, not by habit.
  • Report model performance honestly, including confidence intervals and known failure modes.
  • Identify when a reported metric is measuring the wrong thing — for example, a screening model judged on accuracy.
  • Communicate uncertainty about a model's performance without over-hedging or over-claiming.

Prerequisites assumed by this unit

  • Unit 4 — regression modelling, residuals, R², train/test discipline.
  • Unit 5 — binary classification, predicted probabilities, decision thresholds.
  • Basic descriptive statistics — mean, standard deviation, and the idea of sampling variability.

No new mathematics is introduced in this unit. The difficulty is conceptual, not computational.

03 Reading roadmap

Work through the tutorials in order. Tutorials 1–5 build the metric vocabulary; Tutorials 6–7 build the validation discipline; Tutorial 8 puts both together in a full model-selection workflow.

Unit 6 study sequence
Tutorial Title Core focus Est.
t-01 Why Evaluation Is the Hardest Part The accuracy trap, imbalanced data, evaluating on seen data 25 min
t-02 The Confusion Matrix TP, FP, TN, FN and the language of error 30 min
t-03 Precision, Recall and the F1-Score Two ways to be wrong, and how to balance them 35 min
t-04 ROC Curves and AUC Threshold-free evaluation, ranking quality, what AUC hides 35 min
t-05 Choosing Metrics for Imbalanced Problems Precision–recall curves, class weighting, base rates 30 min
t-06 Cross-Validation k-fold, stratified folds, leakage, nested selection 35 min
t-07 The Bias–Variance Tradeoff and Learning Curves Underfitting, overfitting, complexity, diagnosing from curves 35 min
t-08 Worked Example: Model Selection and Honest Reporting Comparing candidates, confidence intervals, writing the report 30 min
Total guided study time ≈4.5 h

Suggested study sequence

  1. Read the concept, don't skim it Sections 1–5 of each tutorial carry the idea. Slow down on the worked example.
  2. Run the code yourself Every notebook is short. Type it out at least once before you copy-paste it.
  3. Do the self-check before the answer reveal Section 7 exists to catch the misunderstanding while it is still cheap to fix.
  4. Attempt the practice exercises and problem set Sections 8 and 9 are where the skill actually forms.
  5. Write two sentences in the discussion Section 10 asks you to defend an evaluation choice, not just compute a metric.

04 Tutorials

Eight self-contained pages. Each follows the same twelve-section structure — objectives, motivating example, concept, visual, worked example, interactive activity, self-check, practice exercises, problem set, discussion, summary and further reading.

Running example used throughout

Tutorials 1–7 use a synthetic medical screening dataset with a 2% positive rate, deliberately chosen so that accuracy is a useless metric and the precision–recall trade-off is impossible to ignore. Tutorial 8 applies the full workflow to a real dataset.

05 Learning activities

Reading alone will not get you to the outcomes. These are the activities that will.

Guided notebooks Eight short notebooks (nb-17 … nb-24), one per tutorial. Runnable in Jupyter, Colab or any local environment with NumPy, pandas, Matplotlib and scikit-learn.
Metric playboard A single notebook where you move the threshold and watch accuracy, precision, recall, F1, ROC and PR curves all update together. The fastest way to feel why one number is never enough.
Leakage hunt Four deliberately broken pipelines. Find the leak in each one before reading the answer. Used in Tutorial 6.
Peer evaluation review Swap your Assignment 3 evaluation section with a partner and check it against the reporting checklist in Tutorial 8.

Interactive activity — the metric you choose changes the model you ship

In the Tutorial 5 notebook you are given a screening classifier with AUC 0.91 and a 2% base rate. Three stakeholders disagree about what "good" means.

  1. Report accuracy, precision, recall, F1 and average precision at the default 0.5 threshold.
  2. The clinician says a missed case is ten times worse than a false alarm. Which threshold do you recommend, and which metric supports it?
  3. The administrator wants to minimise follow-up appointments. Which threshold do they want?
  4. Explain, in three sentences, why the same model can be simultaneously excellent and unacceptable.
nb-21 · Leakage in the fold Scale the whole dataset before splitting, watch the cross-validation score jump, then fix it and watch it fall back to earth.
from sklearn.datasets import make_classification
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import StratifiedKFold, cross_val_score
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler

X, y = make_classification(
    n_samples=2000, n_features=12, weights=[0.98, 0.02], random_state=42
)

pipe = make_pipeline(StandardScaler(), LogisticRegression(max_iter=1000))
cv = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)

for metric in ("accuracy", "precision", "recall", "f1", "roc_auc"):
    scores = cross_val_score(pipe, X, y, cv=cv, scoring=metric)
    print(f"{metric:>9}: {scores.mean():.3f}")
 accuracy: 0.981
precision: 0.556
   recall: 0.425
      f1: 0.481
  roc_auc: 0.928

Accuracy of 98.1% looks like a finished project. Recall of 42.5% means the model misses more than half of the positive cases. Both numbers describe the same classifier — which one you report determines whether anyone notices.

06 Assessment

Unit 6 completes Module 2. It contributes through the final quiz of the module and through the evaluation sections of Assignment 3, which are assessed here.

0%

Self-checks & practice

Embedded in every tutorial. Formative only — they exist to tell you what you have misunderstood before the graded work.

5%

Quiz 2.3

15 questions, 30 minutes, auto-marked, unlimited attempts until the deadline. Covers Tutorials 1–7.

10%

Assignment 3 — Evaluation & Reporting

The evaluation and reporting sections of the classification analysis, assessed against the Unit 6 checklist.

What the quiz will ask you to do

Outcome Question type Items
The accuracy trap and imbalanced data Calculation, conceptual reasoning 3
Confusion matrix and error types Label a matrix, identify error costs 3
Precision, recall, F1 Calculation, choose a metric for a scenario 4
ROC, AUC and precision–recall curves Interpret a plot, multiple choice 3
Cross-validation and bias–variance Diagnose from a learning curve, short answer 2
Total 15

Assignment 3 — evaluation and reporting sections

  • Part A Problem framing and data preparation — target definition, class balance, leakage check Unit 5
  • Part B Model fitting and evaluation — confusion matrix, metric selection, cross-validation, curves Unit 6
  • Part C Threshold justification, error analysis and honest reporting — costs, uncertainty, limitations Unit 6

Module 2 checkpoint

Unit 6 is the last unit of Module 2. Before moving to Module 3, check that you can complete each of the following. They are the Module 2 outcomes, and the capstone assumes all of them.

Module 2 exit checklist

  • I can frame a supervised problem as regression or classification and justify the choice.
  • I can fit a linear or logistic model and read its coefficients in plain language.
  • I can split data correctly, with preprocessing inside the fold.
  • I can choose an evaluation metric from the cost of each error type.
  • I can diagnose underfitting and overfitting from learning curves.
  • I can write a short, honest report of a model's performance and its limitations.

Academic integrity

You may discuss approaches with classmates, but the notebook and the written analysis must be your own. Any dataset, code fragment or figure you did not produce must be cited.

07 Summary

Unit 6 in one paragraph

Model evaluation is the discipline of producing trustworthy evidence about how a model will behave on data it has not seen. Accuracy is a poor default because it collapses under class imbalance; the confusion matrix, and the precision, recall and F1 metrics derived from it, expose the two distinct ways a classifier can fail. ROC curves and AUC summarise a model's ranking quality across all thresholds, while precision–recall curves are more informative when positives are rare. None of these measurements mean anything unless the data used to compute them was genuinely held out, which is why cross-validation — with all preprocessing performed inside each fold — is the backbone of honest assessment. Finally, the bias–variance tradeoff explains why a model can fail by being too simple or too complex, and learning curves let you tell which failure you are looking at and what to do about it.

Choosing a metric

When each metric is the right one to report
Metric Measures Use when… Danger
Accuracy Fraction of all predictions that are correct Classes are balanced and errors cost the same Collapses on imbalanced data
Precision Of the predicted positives, how many are real A false positive is expensive Can be gamed by predicting almost nothing positive
Recall Of the real positives, how many were found A false negative is expensive Can be gamed by predicting almost everything positive
F1-score Harmonic mean of precision and recall You need one number balancing both Assumes precision and recall matter equally
ROC-AUC Ranking quality across all thresholds Comparing models, threshold not yet chosen Optimistic when positives are very rare
Average precision Area under the precision–recall curve Classes are strongly imbalanced Less familiar to non-specialist audiences
RMSE / MAE Magnitude of regression error The target is continuous Scale-dependent; not comparable across datasets
R² Variance explained relative to the mean Communicating fit to a general audience Not a measure of correctness; rises with extra features

Key terms

Confusion matrix
A four-cell table counting true positives, false positives, true negatives and false negatives.
Precision
TP / (TP + FP) — the proportion of positive predictions that were correct. Also called positive predictive value.
Recall
TP / (TP + FN) — the proportion of actual positives that were found. Also called sensitivity or true positive rate.
Specificity
TN / (TN + FP) — the proportion of actual negatives that were correctly identified. The complement of the false positive rate.
F1-score
The harmonic mean of precision and recall, which penalises a model that is strong on one and weak on the other.
ROC curve
A plot of true positive rate against false positive rate as the decision threshold varies from 1 to 0.
AUC
The area under the ROC curve. Equivalently, the probability that a randomly chosen positive is ranked above a randomly chosen negative.
Precision–recall curve
A plot of precision against recall across thresholds. Preferred over ROC when the positive class is rare.
Cross-validation
Partitioning the data into k folds, training on k−1 and validating on the held-out fold, then averaging. Gives a more stable estimate than a single split.
Data leakage
Any situation where information from outside the training fold influences the model or its evaluation, producing scores that will not generalise.
Bias–variance tradeoff
The tension between a model too simple to capture the signal (high bias, underfitting) and one so flexible it fits the noise (high variance, overfitting).
Learning curve
A plot of training and validation performance against training set size, used to diagnose whether more data would help.

You are ready to move on when…

  • You can look at a confusion matrix and say whether precision or recall is the more urgent problem.
  • You can explain why a cross-validation score is more trustworthy than a single train/test split.
  • You can look at a learning curve and decide whether to collect more data or simplify the model.
  • You can spot a leaky pipeline in under a minute.
  • You can write a model evaluation that a sceptical reader would accept.

Ready to judge a model properly?

Tutorial 1 opens with a fraud detector that is 99% accurate and catches almost nothing. By the end of the unit you will know exactly why — and exactly what to report instead.

👤