How to calculate log loss
For a recorded Yes probability p and an observed outcome y of 1 or 0, binary loss is −[y ln(p) + (1 − y) ln(1 − p)]. When Yes happens, score −ln(p); when No happens, score −ln(1 − p). Lower is better. The mean averages these losses across all supplied records.
The official scikit-learn reference documents the binary formula, natural logarithms and mean normalization. Source reviewed October 12, 2026.
One confident error can change the mean
The fictional rows 70,1; 20,0; 90,0; 40,1 produce losses about 0.356675, 0.223144, 2.302585 and 0.916291. The mean is approximately 0.949674 nats. A constant 50% baseline scores about 0.693147 on every binary outcome, so that baseline does better on these four records.
The 90% forecast for an outcome that did not happen contributes the largest loss. This is why inspecting row results matters. Changing the forecast to 99% makes that one loss about 4.605170; changing it to 100% makes exact loss infinite. These examples do not measure Alphascope, Kalshi or Polymarket performance.
Exact boundaries and explicit clipping
A correct certain forecast has zero exact loss; a wrong certain forecast has infinite exact loss. This calculator evaluates the observed branch directly, avoiding the undefined expression 0 × ln(0). Clipped mode instead bounds probabilities to [10⁻¹⁵, 1 − 10⁻¹⁵]. The finite cap is a numerical convention, not evidence that an impossible prediction was reasonable.
The reference library uses dtype machine precision for clipping. Record the rule used before comparing boundary-heavy results from different tools. Do not silently replace infinite rows, delete them or switch thresholds after seeing the score.
How to calculate log loss in Python
This standard-library example reproduces the four interior-probability rows. It handles exact boundary cases without silently clipping:
from math import log, log1p, inf
records = [(0.70, 1), (0.20, 0), (0.90, 0), (0.40, 1)]
def binary_loss(p, y):
if not 0 <= p <= 1 or y not in (0, 1):
raise ValueError("Use probability 0..1 and outcome 0 or 1")
if (p == 0 and y == 1) or (p == 1 and y == 0):
return inf
return -log(p) if y == 1 else -log1p(-p)
losses = [binary_loss(p, y) for p, y in records]
print(sum(losses) / len(losses)) # about 0.949674Choose the baseline before judging the result
The baseline input applies one chosen probability to every supplied outcome. It defaults to 50% as an illustrative reference, not a claim that 50% is the right baseline for every market. Choose a defensible probability from information available before resolution and document that choice. Fitting a baseline to the scored outcomes gives it hindsight information.
Preserve forecast timestamps, market IDs, outcome definitions and your sampling rule. Compare the same resolved records at the same forecast horizon; keep losing forecasts and describe exclusions. Many observations of one event do not establish a large independent sample.
Inspect a complementary view with the calibration calculator and reliability diagram.
Log loss, Brier score and trading results
The Brier score calculator uses squared probability error. Log loss is unbounded at wrong certainty, so two sets can rank differently under the two metrics. Neither mean alone isolates calibration or proves a forecasting edge.
For prediction-market decisions, keep forecast evaluation separate from executable quotes, fees and liquidity. Use the expected-value calculator for assumed probability versus purchase cost, and read how to evaluate Polymarket accuracy for a careful performance comparison.