Speed

High Bucket Observed Fraction

Average the forecasts inside the high score bucket, compute the conditional positive rate, and avoid dividing by the full dataset size.

The problem

Once forecasts at or above cut have been gathered into the high bucket, we ask two paired questions about that subset alone: what probability did the model promise on average inside the bucket, and what fraction of those same rows finished with y = 1? Both quantities live on the unit interval from zero to one, so they can be compared directly on a single scale.

Take eight scored rows [p, y]: (0.12, 0), (0.22, 1), (0.37, 0), (0.60, 0), (0.70, 1), (0.80, 1), (0.90, 1), and (0.95, 0). At cut = 0.5, the first three rows stay outside the high bucket; the remaining five rows form the group whose high-confidence forecasts are being tested.

Work through the numbers

Select the five rows with p >= 0.5: their forecasts are 0.60, 0.70, 0.80, 0.90, and 0.95, so high_count is 5. Their forecast sum is 0.60 + 0.70 + 0.80 + 0.90 + 0.95 = 3.95, giving a mean predicted probability of 3.95 / 5 = 0.79. Because 0.95 sits near the top without an equally spaced counterweight near 0.50, the bucket mean 0.79 differs from the midpoint 0.75 of [0.5, 1.0].

Now inspect the observed labels y on those same five rows: 0, 1, 1, 1, 0. Three positives occurred among the five high-bucket rows, so the observed positive fraction is 3 / 5 = 0.6. Inside this bucket the model predicted 0.79 on average while positive outcomes arrived at rate 0.6, an overconfidence gap of 0.79 - 0.6 = 0.19.

A frequent denominator slip divides the 3 high-bucket positives by all 8 rows in the table, getting 3 / 8 = 0.375. That ratio measures how often a row is both high-scored and positive across the whole sample, not how often high-scored forecasts come true when issued.

The live model

The top strip marks all eight forecasts, colouring high-bucket negatives blue, high-bucket positives green, and excluded low-bucket rows grey. Below it, the blue bar draws mean_predicted (0.79) and the green bar draws observed_fraction (0.6) on a shared [0.0, 1.0] axis. Lower cut to 0.3 and six rows enter with mean 0.72 and observed fraction 0.5; raise cut to 0.7 (4 rows: 0.8375 vs 0.75) or 0.9 (2 rows: 0.925 vs 0.5).

At cut 0.5, five high-bucket rows have mean predicted probability 0.79 and observed positive fraction 0.6 on a shared zero-to-one bar scale.
let cut = scene.parameter("cut", 0.5, 0.3, 0.9, 0.2);
let p = input.select(1, 0);
let y = input.select(1, 1);
let mask = p.ge(cut).to(DType.F64);
let n_high = mask.sum();
let mean_pred = (p * mask).sum().div(n_high);
let obs_frac = (y * mask).sum().div(n_high);
let items = torch.list().add(n_high).add(mean_pred).add(obs_frac);
let answer = torch.stack(items, 0);
out.set("high_count", n_high.item()).set("mean_predicted", mean_pred.item());
out.set("observed_fraction", obs_frac.item());
{
  "high_count": 5,
  "mean_predicted": 0.7899999999999998,
  "observed_fraction": 0.6
}
Watch the parameter change

Your turn

The observed positive fraction inside [cut, 1] must be conditioned on the rows that actually entered the high bucket. The starting model reports 0.375—the share of all eight dataset rows that are high-bucket positives—instead of the within-bucket positive rate 0.6. Return [n_high, mean_pred, obs_frac]. Check evaluates unseen tables at cut = 0.6 and cut = 0.4 with varying bucket sizes.

Starter divides 3 high-bucket positives by all 8 rows to report 0.375 instead of the conditional high-bucket fraction 0.6.
let cut = scene.parameter("cut", 0.5, 0.3, 0.9, 0.2);
let p = input.select(1, 0);
let y = input.select(1, 1);
let mask = p.ge(cut).to(DType.F64);
let n_high = mask.sum();
let n_all = float(input.size(0));
let mean_pred = (p * mask).sum().div(n_high);
let obs_frac = (y * mask).sum().div(n_all);
let items = torch.list().add(n_high).add(mean_pred).add(obs_frac);
let answer = torch.stack(items, 0);
out.set("high_count", n_high.item()).set("mean_predicted", mean_pred.item());
out.set("observed_fraction", obs_frac.item());
{
  "high_count": 5,
  "mean_predicted": 0.7899999999999998,
  "observed_fraction": 0.375
}

The high bucket's observed rate must measure positives among rows inside [cut, 1] alone. The starting model dilutes that rate across the entire table and reports 0.375 instead of 0.6. Return [n_high, mean_pred, obs_frac].

Once conditioned on the five high-bucket rows, the green bar lengthens from 0.375 to 0.6 and the returned vector becomes [5, 0.79, 0.6].

Read the result carefully

At cut = 0.9, only (0.90, 1) and (0.95, 0) remain inside the high bucket, so one negative outcome swings observed_fraction all the way to 1 / 2 = 0.5. Even if a model truly had 0.925 success probability on those two cases, two independent trials can land on 1 positive out of 2 without proving structural miscalibration. Always read the observed fraction alongside high_count so small-sample fluctuations are not mistaken for systematic bias.

Recap

  • Compute both mean_predicted and observed_fraction over the masked high-bucket subset so both share denominator n_high.
  • Use the actual average of forecasts in the bucket (0.79) rather than the geometric bin midpoint (0.75).
  • Check high_count before interpreting a gap, since two or three rows have wide binomial variability.