Skip to content
svgpredicted-distributions

Predicted distributions

What does a probabilistic model predict for individual rows, and how likely was what actually happened?

Demo data · seed 20261101 · 405 rows · default settings · 640 × 360SVG, lightSVG, darkDemo CSV

How to read it

  1. Read each curve as the full distribution the model predicts for one row; its peak is the most likely value.
  2. Read a curve's width as the model's uncertainty for that row: narrow is confident.
  3. Follow the dashed line up from the actual value: its height is the likelihood the model gave to what happened.
  1. Callout 1: A narrow, tall curve: a confident prediction.
  2. Callout 2: A wide, low curve: an uncertain one.
  3. Callout 3: Dashed line: the density at the actual value.

Watch out

  • Five rows are an illustration, not evidence; check 90% coverage and the NLL or CRPS across held-out rows.
  • The chosen distribution shapes every curve. A Normal can put weight on impossible negative values.

Defaults

Counts (stems)
Off
Draw probability masses as stems, for a count distribution such as the Poisson.

Pinned in the code

  • Draws the numbers the learner published (training history, member predictions, predicted densities); the chart computes nothing statistical.
  • Curves are evaluated by the learner on a grid of target values (81 points spanning ±3.5 SD of the shown rows, or every count for the Poisson).
  • A tall curve is a confident prediction; the dashed line's height is the likelihood of the actual value — the quantity the log score rewards.
# Predicted distributions — Codesplash Chart Lab (recipe "predicted-distributions")
# controls: discrete=false
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

try:
    import codesplash as cs  # optional: the app's chart theme
except ImportError:
    cs = None
if cs:
    cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]
# non-colour encodings per series (same table as the app: series are never told apart by colour alone)
SERIES_DASHES = ["-", (0, (6, 3)), (0, (1.5, 2.5)), (0, (8, 3, 2, 3)), (0, (12, 4)), (0, (3, 3)), (0, (8, 2, 2, 2, 2, 2)), (0, (1.5, 5))]
SERIES_MARKERS = ["o", "s", "^", "D", "P", "*", "2", "v"]

df = pd.read_csv("predicted-distributions-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["row"] = pd.Categorical(df["row"].astype("string"), categories=["row 12 (actual 25.1)", "row 47 (actual 19.3)", "row 3 (actual 50.6)", "row 88 (actual 88.2)", "row 61 (actual 72.8)"])

def levels_of(s):
    """Declared level order (categoricals), else order of first appearance."""
    if isinstance(s.dtype, pd.CategoricalDtype):
        return [v for v in s.cat.categories if (s == v).any()]
    return list(dict.fromkeys(s.dropna().astype(str)))
X = "ozone (ppb)"
D = "density"
S = "row"
A = "actual"
DISCRETE = False
series = levels_of(df[S])
fig, ax = plt.subplots(figsize=(7, 4.2))
for i, s in enumerate(series):
    d = df[df[S].astype(str) == s].sort_values(X)
    colour = PALETTE[i % len(PALETTE)]
    if DISCRETE:
        off = (i - (len(series) - 1) / 2) * 0.14  # side by side at each count
        ax.vlines(d[X] + off, 0, d[D], color=colour, linewidth=1.2)
        ax.plot(d[X] + off, d[D], SERIES_MARKERS[i % 8], color=colour, markersize=3, label=s)  # marker shape per row, as in the app
    else:
        ax.fill_between(d[X], 0, d[D], color=colour, alpha=0.08, linewidth=0)
        ax.plot(d[X], d[D], color=colour, linewidth=1.6, linestyle=SERIES_DASHES[i % 8], label=s)  # dash per row, as in the app
    if A and d[A].notna().any():
        a = float(d[A].dropna().iloc[0])
        top = float(np.interp(a, d[X], d[D])) if not DISCRETE else float(d[D].max()) * 0.08
        ax.vlines(a, 0, top, color=colour, linestyle="--", linewidth=1.1)  # height = likelihood of the actual
        if not DISCRETE:
            ax.plot([a], [top], SERIES_MARKERS[i % 8], markerfacecolor="white", markeredgecolor=colour, markersize=6)  # the row's marker at the actual
ax.set_ylim(bottom=0)
ax.set_xlabel(X)
ax.set_ylabel(D)
ax.legend(frameon=False, fontsize=8)
plt.show()

Needs pandas, numpy, matplotlib · reads predicted-distributions-demo.csv · app theme from the optional codesplash helper