Speed

What F1 Does and Does Not Say

Break an exact F1 = 0.60 tie between [3, 1, 3, 23] and [6, 8, 0, 16] with F_beta while noting TN blindness.

The problem

Suppose we tighten Grid B's cutoff until its false alarms drop from 18 to 8, producing Grid C ([TP, FP, FN, TN] = [6, 8, 0, 16]) on our same 6-positive, 24-negative benchmark. Grid A ([3, 1, 3, 23]) has F1 = 6 / 10 = 0.60, and Grid C has F1 = 12 / (12 + 8 + 0) = 12 / 20 = 0.60 — another exact tie. Does F1 = 0.60 mean the two classifiers are interchangeable?

We generalize F1 to F_beta = (1 + beta^2) * TP / ((1 + beta^2) * TP + beta^2 * FN + FP) across beta from 0.5 to 2.0 to see what F1 says and what it leaves unsaid.

Work through the numbers

Compare Row 0 ([3, 1, 3, 23], P = 0.75, R = 0.50) and Row 1 ([6, 8, 0, 16], P = 3/7 ≈ 0.429, R = 1.00):

  • `beta = 1.0` (`beta^2 = 1.0`, equal weight): Row 0 scores 6 / (6 + 3 + 1) = 0.600; Row 1 scores 12 / (12 + 0 + 8) = 0.600.
  • `beta = 0.5` (`beta^2 = 0.25`, precision prioritized): Row 0 rises to 3.75 / (3.75 + 0.75 + 1) = 15 / 22 ≈ 0.682, beating Row 1's 7.50 / (7.50 + 0 + 8) = 15 / 31 ≈ 0.484.
  • `beta = 2.0` (`beta^2 = 4.0`, recall prioritized): Row 0 falls to 15 / (15 + 12 + 1) = 15 / 28 ≈ 0.536, losing to Row 1's 30 / (30 + 0 + 8) = 15 / 19 ≈ 0.789.

Changing beta flips the winner by +0.198 in one direction (beta = 0.5) and -0.254 in the other (beta = 2.0) without changing a single prediction.

The live model

Two horizontal bars display F_beta for cautious Grid A ([3, 1, 3, 23], amber) and recall-first Grid C ([6, 8, 0, 16], green), above a card showing active beta^2 weight on FN and the untouched TN cells (23 vs 16). Drag beta from 0.5 to 2.0: the bars cross at beta = 1.0 (0.60 tie), favoring Grid A below 1.0 and Grid C above 1.0.

Two equal F_beta bars at 0.6 for Grid A [3, 1, 3, 23] and Grid C [6, 8, 0, 16] when beta is 1.0.
let beta = scene.parameter("beta", 1.0, 0.5, 2.0, 0.5);
let tp = input.slice(1, 0, 1);
let fp = input.slice(1, 1, 2);
let miss_pos = input.slice(1, 2, 3);
let b2 = beta * beta;
let num = tp * (1.0 + b2);
let den = num + miss_pos * b2 + fp;
let answer = num.div(den);
out.set("f_beta", answer);
{
  "f_beta": [
    [
      0.6
    ],
    [
      0.6
    ]
  ]
}

Your turn

Compute the [2, 1] column answer of F_beta scores for both rows using b2 = beta * beta. The starter writes tp instead of num (tp * (1.0 + b2)) inside the denominator. Check tests unseen two-row confusion matrices at beta = 2.0 and beta = 0.5.

Starter model uses unscaled tp in the denominator, inflating both F_beta bars to 0.857 at beta 1.0.
let beta = scene.parameter("beta", 1.0, 0.5, 2.0, 0.5);
let tp = input.slice(1, 0, 1);
let fp = input.slice(1, 1, 2);
let miss_pos = input.slice(1, 2, 3);
let b2 = beta * beta;
let num = tp * (1.0 + b2);
let den = tp + miss_pos * b2 + fp;
let answer = num.div(den);
out.set("f_beta", answer);
{
  "f_beta": [
    [
      0.8571428571428571
    ],
    [
      0.8571428571428571
    ]
  ]
}

Compute the [2, 1] column answer of F_beta scores using num = tp * (1.0 + b2) and den = num + miss_pos * b2 + fp.

Read the result carefully

F1 says one clear thing: whether a classifier achieves high precision and high recall simultaneously without letting either rate collapse. Three critical facts remain outside binary F1's reach:

  • Asymmetric error costs: F1 weights FP and FN 1:1 in 2*TP + FP + FN. When recall is beta times as important as precision (missing a positive costs beta^2 = 4 times a false alarm), F2 encodes that preference explicitly; when false actions are expensive, F0.5 (beta^2 = 0.25) protects precision.
  • True-negative blindness: neither F1 nor F_beta ever reads TN (23 vs 16). Appending 10,000 routine negatives (TN) leaves every F_beta bar unchanged, so pair F_beta with specificity or false-positive rate when negative volume matters.
  • Zero true positives: when TP = 0, the rate formula 2 * P * R / (P + R) evaluates to 0 / 0, whereas the count formula 2 * TP / (2 * TP + FP + FN) gives 0 as soon as FP + FN > 0; standard evaluation reports adopt the count convention (F1 = 0 when TP = 0 and FP + FN > 0) and state how they treat TP = FP = FN = 0.

With more than two classes, there is no single F1 score: reports distinguish per-class F1 (scoring each class one-versus-rest), macro F1 (the plain unweighted mean of the per-class scores), micro F1 (computed from TP, FP, and FN pooled across all classes), and weighted F1 (averaging per-class scores weighted by each class's true size), which diverge sharply under class imbalance.

Recap

  • Grid A ([3, 1, 3, 23]) and Grid C ([6, 8, 0, 16]) share 6 positives and 24 negatives and tie at F1 = 0.60.
  • F_beta weights FN by beta^2 relative to FP: beta = 0.5 picks Grid A (0.682 vs 0.484), whereas beta = 2.0 picks Grid C (0.789 vs 0.536).
  • Neither F1 nor F_beta inspects TN, and plain F1 assumes equal cost per false positive and false negative.