Exercise: Choose a threshold under unequal error costs#
A screening system must identify uncommon positive cases. Accuracy alone may reward a system that never identifies one.
See the shared submission guidance and rubric. Run from book/exercises; the setup below supplies data, not completed answers.
# Shared simulator and small utility functions; no live service is called.
source("../R/course.R")
set.seed(113)
d <- data.frame(score=rnorm(1200))
d$y <- rbinom(nrow(d),1,plogis(-2.5+1.4*d$score))
ids <- sample(seq_len(nrow(d)))
train <- d[ids[1:600], ]; validation <- d[ids[601:900], ]; test <- d[ids[901:1200], ]
false_negative_cost <- 8
false_positive_cost <- 1
1. Establish probability and decision baselines#
Fit logistic regression on train. Compare validation Brier score and log loss with a constant training-prevalence predictor. Also compute accuracy and recall for an always-negative decision rule. Explain why the decision baseline and the probability baseline are different objects.
# Fit the model and calculate both types of baseline.
Your explanation and evidence:
2. Select a decision rule#
On validation only, evaluate thresholds from .05 to .95 in steps of .05 using cost = 8*FN + FP. Plot cost and select a threshold, declaring a tie rule. Compare its confusion matrix with threshold .5. Explain which error the selected rule trades for which benefit.
# Select and freeze a threshold from validation costs.
Your explanation and evidence:
3. Evaluate once and inspect calibration#
Apply the frozen model and threshold to test. Report the confusion matrix, recall, precision, accuracy, cost per case, Brier score, and a five-bin reliability plot with bin counts. Discuss instability in small bins and why the test threshold must not be retuned.
# Evaluate held-out probabilities and decisions, keeping them distinct.
Your explanation and evidence:
What to submit#
A validation cost curve, a final test metric table, and a calibration plot. Recommend a decision rule conditional on the stated costs and population prevalence.