Build a Calibration Table for Event Probabilities
If you have read our post on implied probability, you already know how to turn a market price into a number between 0 and 1. A calibration table answers a different question: when your forecast says 70 percent, does the event actually happen about 70 percent of the time? This post builds that table in Python, keeps the empty and sparse bins visible, and is strict about what calibration does and does not tell you.
What a calibration curve measures
Calibration compares your probabilistic predictions against realized outcomes. In scikit-learn terms, a calibration curve (also called a reliability diagram) discretizes the [0, 1] interval into bins, plots the fraction of positives in each bin on the y-axis, and plots the mean predicted probability on the x-axis. The gap between those two values in a given bin is your miscalibration.
The mechanic is binning. You place predictions into buckets by their stated probability, then measure how often the event actually happened inside each bucket. That observed frequency is what you compare to your average prediction. When the two align across bins, your forecasts are calibrated.
A hypothetical forecast and outcome set
Everything below is a made-up example chosen to illustrate the mechanics. These are not market observations, not backtested values, and not a forecast. Suppose you logged a forecast p for each of a set of resolved yes/no questions, and recorded the outcome y as 1 if the event happened and 0 if it did not.
# Hypothetical labeled data. Not real markets.
# p = your stated probability, y = realized outcome (1=yes, 0=no)
samples = [
(0.05, 0), (0.08, 0), (0.11, 0), # low-prob bin
(0.52, 1), (0.49, 0), (0.55, 1), (0.47, 0),# mid bin
(0.71, 1), (0.69, 1), (0.74, 0), (0.70, 1),# high bin
(0.93, 1), # very-high bin, sparse
]Binning by hand so empty bins stay visible
Scikit-learn's calibration_curve(y_true, y_prob, n_bins=10, strategy='uniform') returns the fraction of positives and the mean predicted probability per non-empty bin. One behavior matters for honest research: bins with no samples are not returned, so the output array can have fewer entries than n_bins. That silent dropping hides where you have no evidence. For research you usually want the opposite, so compute the table yourself and keep every bin.
from collections import defaultdict
def calibration_table(samples, n_bins=10):
edges = [i / n_bins for i in range(n_bins + 1)]
counts = defaultdict(int)
positives = defaultdict(int)
psum = defaultdict(float)
for p, y in samples:
b = min(int(p * n_bins), n_bins - 1) # p=1.0 lands in last bin
counts[b] += 1
positives[b] += y
psum[b] += p
rows = []
for b in range(n_bins):
n = counts[b]
obs = positives[b] / n if n else None # observed frequency
avg_p = psum[b] / n if n else None # mean prediction
rows.append((edges[b], edges[b+1], n, avg_p, obs))
return rows
for lo, hi, n, avg_p, obs in calibration_table(samples):
print(f"[{lo:.1f},{hi:.1f}) n={n:>2} avg_p={avg_p} obs_freq={obs}")The table that falls out of the hypothetical data above has empty bins (for example the 0.2 to 0.4 range, where you made no forecasts) and sparse bins (the 0.9 to 1.0 range, with a single sample). Keep them. An empty bin is not a calibration result, it is an absence of evidence. A bin with one observation gives an observed frequency of either 0 or 1, which tells you almost nothing. Reporting bin counts next to observed frequencies is the whole point: the frequency is only as trustworthy as the count beside it.
Reading the hypothetical table
- Dense, on-diagonal bins (average prediction near observed frequency with a healthy count) are the only ones that support a calibration claim.
- Off-diagonal dense bins suggest systematic over- or under-confidence in that probability range.
- Sparse bins (n of 1 or 2) should be flagged, not interpreted. Consider wider bins or the quantile strategy, where bins hold roughly equal sample counts instead of equal widths.
- Empty bins mean you have never tested that probability range. Say so explicitly rather than interpolating.
Observation timing is part of the data
A calibration table is only meaningful if every prediction was recorded before the outcome was known, and at a consistent point in each event's life. A probability stamped one minute before resolution is not comparable to one stamped a week out. Fix the observation moment (for example, a set number of hours before expected resolution) and record the timestamp with every forecast. Mixing horizons blends different information states into the same bin and quietly corrupts the frequencies.
Calibration is not trading profitability
This is the claim people most often get wrong. A perfectly calibrated forecaster can still lose money, and a poorly calibrated one can still make it. Calibration measures whether your stated probabilities match long-run frequencies. Profit depends on the price you could actually transact at, fees, fill timing, position limits, and slippage, none of which appear in a reliability diagram. A table that sits exactly on the diagonal tells you your probabilities are honest. It tells you nothing about edge versus a market price or whether an order would have filled.
Where paper research fits
Once a calibration table suggests your probabilities are trustworthy in some range, the next question is execution, and that is a separate model with its own assumptions. Banger is a paper-only research beta that runs code-first strategies against current Polymarket and Kalshi market data, with simulated fills, logs, and risk controls, and without venue keys. Treat any paper result as evidence under a specific data, fill, and fee model, not proof of real-venue execution or profit. Keep the two analyses separate: calibration tells you whether your forecasts are honest; a paper experiment, with all its stated limits, is where you probe whether that honesty survives contact with prices, fees, and fills.
Start your calibration work from the primary source: the scikit-learn probability calibration guide at scikit-learn.org/stable/modules/calibration.html. If you want to explore bounded paper experiments after your forecasts check out, you can sign up at bangertrades.com. No fills, returns, or outcomes are promised.