Contents
07Interview follow-ups
7.1How do you choose the threshold?
From costs. Suppose the model’s p=p(y=1\mid x) is a calibrated probability, a false alarm costs C_{\mathrm{FP}} (a phone call to the customer) and a missed fraud costs C_{\mathrm{FN}} (the stolen amount, the dispute).
Proposition 4 (The cost-optimal threshold, Murphy, 2022, eq. 5.10). Flagging has expected cost (1-p)\,C_{\mathrm{FP}} and passing has expected cost p\,C_{\mathrm{FN}}. Flagging is cheaper exactly when
If we flag, we pay C_{\mathrm{FP}} when the transaction is legitimate, which happens with probability 1-p. If we pass, we pay C_{\mathrm{FN}} when it is fraud, with probability p. Flag when (1-p)C_{\mathrm{FP}}\le pC_{\mathrm{FN}}, that is, C_{\mathrm{FP}}\le p(C_{\mathrm{FP}}+C_{\mathrm{FN}}), which is (12).
When correct decisions also cost something (reviewing a caught fraud still takes an analyst’s time), the same argument gives \tau^*=(C_{\mathrm{FP}}-C_{\mathrm{TN}})/(C_{\mathrm{FP}}-C_{\mathrm{TN}}+C_{\mathrm{FN}}-C_{\mathrm{TP}}) (Elkan, 2001). If a missed fraud costs c times a false alarm, \tau^*=1/(1+c); the threshold 0.5 is right only when both mistakes cost the same. With c=25, \tau^*=1/26=0.038. Counting one unit per false alarm and 25 per missed fraud, the test day costs 5{,}275 for the lazy model, 2{,}370 at \tau=0.5 (45+25\times93) and 1{,}662 at \tau=1/26 (312+25\times54); the lowest cost achievable at any threshold is 1{,}597 (Figure 6a).
The formula needs calibrated probabilities. When they are not trusted, or the costs are only roughly known, choose the threshold on validation data, never on the test set (Episode 11). We computed out-of-fold scores on day 1 (stratified 5-fold cross-validation) and picked the threshold with the lowest validation cost: \tau=0.028, close to 1/26, which costs 1{,}668 on the test day. Picking instead the threshold with the best validation F_1 gives \tau=0.084 and a test F_1 of 0.593; the best F_1 on the test day, 0.659 near \tau=0.2, is not available to an honest procedure, because finding it requires looking at the test labels.
There is also a geometric view (Fawcett, 2006, §6), (Provost and Fawcett, 2001). With \pi the prevalence (the share of frauds), the expected cost per transaction at a ROC point is C_{\mathrm{FN}}\,\pi\,(1-\mathrm{TPR})+C_{\mathrm{FP}}\,(1-\pi)\,\mathrm{FPR}. Points of equal cost lie on straight lines \mathrm{TPR}=m\,\mathrm{FPR}+\text{const} with slope m=C_{\mathrm{FP}}(1-\pi)/(C_{\mathrm{FN}}\,\pi), and the best operating point is where the highest such line touches the ROC curve. Rare positives make m large (26.5 for our costs and prevalence), so the best point sits on the steep left part of the curve, again the region that the ROC plot compresses.
7.2Does a high AUC mean good probabilities?
No. AUC depends only on the order of the scores (Proposition 2). Squash every score into [0.49,0.51] while keeping the order: the AUC stays 0.958, but every transaction now gets a fraud probability of about 50\%, while the real rate is 0.15\%. The log loss of Episode 8, -\frac1n\sum_i[y_i\log p_i+(1-y_i)\log(1-p_i)], sees the difference at once: 0.0046 for the model’s scores, 0.693 (that is, \ln2) for the squashed ones, worse even than the constant prediction p=\pi (0.0113). The model’s own scores are roughly calibrated: their mean is 0.185\% against a real fraud rate of 0.151\%, and in Figure 6b the binned predictions lie close to the diagonal. Ranking (AUC, AP) and calibration (log loss, Brier score, reliability diagrams) are different properties; a cost-based threshold like (12) needs both.
7.3More than two classes?
Compute precision, recall and F_1 for each class against the rest, then average. Macro averaging takes the plain mean of the per-class scores, so every class counts equally, however rare. Micro averaging pools the counts \mathrm{TP}, \mathrm{FP}, \mathrm{FN} of all classes first and then computes one score; when each example has exactly one label, every mistake is a false positive for one class and a false negative for another, so micro-F_1 equals accuracy. Treating our two classes this way at \tau=0.5: F_1 is 0.631 for fraud and 0.9995 for legitimate, so macro-F_1=0.815, while micro-F_1=99.90\%, the accuracy. For the lazy model, macro-F_1=0.500 and micro-F_1=99.85\%. Use macro averages when the rare classes matter. For AUC, the one-against-rest areas can be averaged, or the pairwise version of Hand and Till (2001) used.
Pause and think. Why would a model chosen by the best cross-validated F_1 on day 1 do worse on day 2?
Show the answer
Two reasons. The threshold that maximizes F_1 on one sample is itself fitted to that sample’s noise; with only 281 frauds on day 1, the best threshold is uncertain. And fraud changes from day to day: the day-1 out-of-fold F_1 was 0.78 and the test-day F_1 at the same threshold 0.59. Report the test number, and expect drift in production.