Speed

Positive Recall Is Zero

Restrict the denominator to actual positive rows so true negatives can no longer hide missed positive cases.

The problem

Accuracy reached four out of five on our imbalanced table because four true negatives outweighed the single missed positive row. Whenever missing a positive outcome is the failure we care about, true negatives have no business sitting in the numerator *or* the denominator of the detection rate.

Positive recall—also called sensitivity or the true-positive rate—asks one restricted question: out of all rows whose true label is 1, what fraction did the classifier predict as 1? On [0.10, 0], [0.15, 0], [0.35, 1], [0.20, 0], and [0.42, 0], we compute [TP, FN, positive_recall] across thresholds.

Work through the numbers

Positive recall divides TP by total actual positives TP + FN. Notice that TN and FP are completely absent from the formula:

  • At threshold = 0.6 and threshold = 0.5, row 2 (0.35, true 1) falls below the cutoff, so TP = 0, FN = 1, and positive recall is 0 / (0 + 1) = 0.0.
  • At threshold = 0.4, row 4 (0.42, true 0) flips to a false positive, yet row 2 is still missed: TP = 0, FN = 1, and positive recall remains 0 / 1 = 0.0.
  • At threshold = 0.3, 0.2, and 0.1, row 2 exceeds the cutoff: TP = 1, FN = 0, and positive recall jumps to 1 / (1 + 0) = 1.0.

Dividing TP by all 5 rows instead of TP + FN would report 1 / 5 = 0.2 at threshold = 0.3, confusing joint prevalence with conditional detection rate. Meanwhile, if a table ever contained zero actual positives (TP + FN = 0), positive recall would be 0 / 0 and undefined rather than zero.

The live model

The diagram isolates the actual-positive pool into caught TP (green) and missed FN (red) counters, then plots positive recall on a zero-to-one bar alongside negative specificity TN / (TN + FP) for contrast. Move threshold from 0.5 to 0.3 to see positive recall jump from 0.0 to 1.0 while negative specificity steps from 4 / 4 = 1.0 down to 3 / 4 = 0.75.

At threshold 0.5, TP is 0, FN is 1, positive recall is 0, and negative specificity is 1.
let threshold = scene.parameter("threshold", 0.5, 0.1, 0.6, 0.1);
let prob = input.select(1, 0);
let label = input.select(1, 1);
let pred = prob.gt(threshold).to(DType.F64);
let neg_pred = pred.rsub(1.0);
let neg_label = label.rsub(1.0);
let tp = (pred * label).sum();
let miss_pos = (neg_pred * label).sum();
let tn = (neg_pred * neg_label).sum();
let specificity = tn.div(neg_label.sum());
let recall = tp.div(tp + miss_pos);
let parts = torch.list().add(tp.reshape(1)).add(miss_pos.reshape(1));
let answer = torch.cat(parts.add(recall.reshape(1)), 0);
out.set("specificity", specificity).set("recall_summary", answer);
{
  "specificity": 1,
  "recall_summary": [
    0,
    1,
    0
  ]
}
Watch the parameter change

Your turn

Fix recall inside [tp, miss_pos, recall] so it divides tp by actual positives tp + miss_pos. The starting model divides tp by all rows N, understating recall whenever negative rows exist. Check runs unseen tables with multiple positive rows and thresholds where precision and recall also differ.

Starter model divides TP by all rows instead of actual positives TP + FN.
let threshold = scene.parameter("threshold", 0.5, 0.1, 0.6, 0.1);
let prob = input.select(1, 0);
let label = input.select(1, 1);
let pred = prob.gt(threshold).to(DType.F64);
let neg_pred = pred.rsub(1.0);
let neg_label = label.rsub(1.0);
let tp = (pred * label).sum();
let miss_pos = (neg_pred * label).sum();
let tn = (neg_pred * neg_label).sum();
let specificity = tn.div(neg_label.sum());
let recall = tp.div(float(label.numel()));
let parts = torch.list().add(tp.reshape(1)).add(miss_pos.reshape(1));
let answer = torch.cat(parts.add(recall.reshape(1)), 0);
out.set("specificity", specificity).set("recall_summary", answer);
{
  "specificity": 1,
  "recall_summary": [
    0,
    1,
    0
  ]
}

Compute [tp, miss_pos, recall] under rule prob > threshold so recall divides caught positives tp by total actual positives.

Read the result carefully

Positive recall solves the blind spot of raw accuracy, yet it has an opposite blind spot of its own: because FP never enters TP / (TP + FN), setting threshold below every score always achieves 1.0 positive recall by flagging the entire table. Pairing positive recall with false-positive counts, specificity, or precision prevents a trivial Always-P rule from looking perfect.

At the default threshold = 0.5 nothing is flagged (TP + FP = 0), so precision TP / (TP + FP) is 0 / 0 on this table: undefined, not 0.

Recap

  • Positive recall equals TP / (TP + FN), conditioning strictly on actual positive rows.
  • At threshold = 0.5, positive recall is 0 / 1 = 0.0 on the exact run where accuracy is 0.8.
  • Positive recall ignores FP and TN, so it must be read alongside false-alarm measures rather than in isolation.