Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Chapter 11 — Assignment Project: Choosing the Metric for a Screening Test

Open in Colab

Overview

A health service wants a model that flags patients for a follow-up test for a rare disease (about 2% of patients). A missed case is serious; a false alarm costs one extra appointment. Your job is not only to train a model, but to decide how it should be judged and where its threshold should be, and to tell the service what to expect.

The data are generated below (so that everyone has the same), with a fixed test set you must use only in Part D.

PartTaskPoints
AWhy accuracy fails here15
BCurves: ROC against precision–recall20
CRemedies: threshold, weights, resampling25
DA threshold from the costs, and an honest report25
EA one-page memo15

Part A — Why Accuracy Fails (15 points)

  1. Compute the cross-validated accuracy (5-fold, stratified, on the development set) of a model that always predicts “healthy”, and of a logistic regression at threshold 0.5.

  2. For the logistic regression, give the confusion matrix (from cross_val_predict), the precision, the recall and the balanced accuracy.

  3. In three sentences, explain to a non-specialist why the accuracy is misleading here.

Your explanation:


Part B — ROC Against Precision–Recall (20 points)

  1. Add a random forest (300 trees) and compute its cross-validated probabilities the same way.

  2. For both models, report ROC AUC and average precision, and plot both curves side by side.

  3. Which metric separates the two models more clearly? Which would you show the health service, and why?

Your answer:


Part C — Remedies (25 points)

For the better model of Part B, compare on the development set (cross-validated):

  1. the default threshold of 0.5;

  2. the threshold that maximises F2F_2 (recall counts twice as much as precision);

  3. class_weight='balanced' (or 'balanced_subsample' for a forest) with the threshold 0.5.

Report precision, recall, F2F_2 and the mean predicted probability for each. What does the last column tell you about the probabilities of option 3?

Your comparison:


Part D — A Threshold From the Costs (25 points)

The service estimates that a missed case costs as much as 40 unnecessary appointments.

  1. On the development set’s cross-validated probabilities, find the threshold that minimises 40⋅FN+FP40 \cdot FN + FP.

  2. Refit the chosen model on the whole development set, and apply that threshold to the test set, once. Report the confusion matrix, recall, precision and the total cost.

  3. Give a 95% bootstrap interval for the test recall (1 000 resamples).

Your report:


Part E — Memo (15 points)

One page for the health service: the metric you optimised and why; the threshold and what it means in patients (out of 1 000 patients, how many flagged, how many cases found, how many missed); the uncertainty; and one thing that would make you change the threshold.

Grading Rubric

CriterionExcellentAdequateInsufficient
A (15)correct numbers, a clear plain-language explanationnumbers onlyaccuracy defended
B (20)both curves, the right metric argued from the imbalancenumbers without argumentROC only
C (25)three options compared, the probability distortion explainedoptions without interpretationmissing
D (25)threshold chosen on development data, test used once, interval givenno intervalthreshold chosen on the test set
E (15)concrete, in patients, honest about uncertaintygenericmissing