Session · 105 min · Available now · Modeling & Inference

HOT START OR REAL?

Hierarchical Modeling using PyMC in Baseball

Rate every hitter on a roster, including the one with twelve plate appearances, with partial pooling in PyMC.

An agent can write the model. This session is about knowing when it is wrong.

$79 Buy now Buy once, watch any time. A person answers if it is the wrong one for you.
What you learn

The skills, and the artifact you leave with.

  • Write a hierarchical model where each hitter's rate is drawn from a league distribution
  • Choose priors you can defend and check them with prior predictive draws
  • Read shrinkage: who moved toward the league and by how much, and why that is right
  • Report each rating as an interval and the hot start as a posterior probability
You leave with

A fitted hierarchical model over a real roster with a shrinkage plot and a one-line answer to how much of a hot start to believe.

Pythonagents/viz/S3.py
2026-11-09T02:12:15.852989 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ 0.10 0.15 0.20 0.25 0.30 0.35 batting average Ivanescu Brannagh Quillon Dunmarrow Quintavalle Pemberly Galloway-Cruz Castellane Wyndholt Brannagh Larkspur Sorrento-Vale Brannagh Wyndholt Brannagh Strathley Galloway-Cruz Strathley Penhallow group 0.249 Hot start, or real? The pull toward the group, and what happened next first 45 at-bats posterior mean (Beta-Binomial, group prior) rest of the season
Nineteen hitters after 45 at-bats: the raw average, the Beta-Binomial posterior mean, and what the rest of the season did. Drawn at build from the data on this site by the code below.
The code that drew it
# Nineteen hitters after 45 at-bats: the raw average, the Beta-Binomial posterior mean, and what the rest of the season did.
import sys, pathlib, csv
sys.path.insert(0, str(pathlib.Path(__file__).parent))
from _palette import plt, emit, GOLD, TEAL, AQUA, CREAM, MUTE

rows = list(csv.DictReader(open("site/18-practice/hot-start-hitters/files/batting_2026.csv")))
ab = [int(r["at_bats"]) for r in rows]; h = [int(r["hits"]) for r in rows]
rab = [int(r["remaining_at_bats"]) for r in rows]; rh = [int(r["remaining_hits"]) for r in rows]
raw = [hi / a for hi, a in zip(h, ab)]
rest = [rhi / ra for rhi, ra in zip(rh, rab)]
# a Beta prior fitted to the group by the method of moments: the league the hitters are drawn from
m = sum(raw) / len(raw); v = sum((x - m) ** 2 for x in raw) / (len(raw) - 1)
k = m * (1 - m) / v - 1; a0, b0 = m * k, (1 - m) * k
post = [(a0 + hi) / (a0 + b0 + a) for hi, a in zip(h, ab)]

order = sorted(range(len(rows)), key=lambda i: -raw[i])
fig, ax = plt.subplots(figsize=(7.2, 4.2))
y = list(range(len(order)))
for yi, i in zip(y, order):
    ax.plot([raw[i], post[i]], [yi, yi], color=MUTE, lw=1, zorder=1)
ax.scatter([raw[i] for i in order], y, color=AQUA, s=28, zorder=3, label="first 45 at-bats")
ax.scatter([post[i] for i in order], y, color=GOLD, s=34, zorder=4, label="posterior mean (Beta-Binomial, group prior)")
ax.scatter([rest[i] for i in order], y, color=CREAM, s=18, marker="D", zorder=5, label="rest of the season")
ax.axvline(m, color=MUTE, lw=1, ls="--"); ax.text(m, -0.9, f"group {m:.3f}", color=MUTE, ha="center", fontsize=9)
ax.set_yticks(y); ax.set_yticklabels([rows[i]["name"].split()[-1] for i in order], fontsize=8.5)
ax.invert_yaxis(); ax.set_xlabel("batting average"); ax.set_title("Hot start, or real? The pull toward the group, and what happened next")
ax.legend(loc="lower right", fontsize=8.5, frameon=False)
emit(fig)

Data: Hot-start hitters. Simulated for practice by AthlyticZ (agents/sim_data.py, seed 20261109). License CC BY 4.0.

The problem

Forty plate appearances into a season, one hitter is far above his career line, and the same method has to rate the hitter with twelve plate appearances too.

Three decisions it teaches
  1. The model: every hitter's rate drawn from a league distribution whose spread is estimated, not assumed
  2. The priors: what to choose, how to defend them, and how to check them with prior predictive draws
  3. The reading: how far each hitter moved toward the league, why that is right, and how to report it as an interval

The artifact. A fitted hierarchical model over a real roster with a shrinkage plot and a one-line answer to how much of a hot start to believe.

Curriculum
  1. Hierarchical Modeling using PyMC in Baseball

    One live session, recorded, 105 minutes. Yours to keep and watch any time.

What you get

Everything that exists for this session, and nothing that does not.

  • The recording105 minutes, yours to keep
  • The datasetsHot-start hitters, with three practice questions each
Play with the data

Run the code, in your browser.

The chart on this page, drawn by code you can edit. R runs on webR and Python on Pyodide; nothing loads until you press Run, and nothing you type leaves the page.

This chart is the code's result. Run recomputes it in your browser.
Each hitter's posterior batting average after 45 at-bats, shaded to the 90% credible interval; the diamond is what they hit the rest of the season.

Edit me: Move the prior strength, or edit prior_strength and run: watch the hot starts pull toward the group.

Data: Hot-start hitters (batting_2026.csv). Simulated for practice by AthlyticZ (agents/sim_data.py, seed 20261109). License CC BY 4.0.

The code runs in your browser on webR or Pyodide; nothing you type leaves the page.

Curriculum

What is covered, in order.

From the academy course record, as it is taught.

  1. Hierarchical Modeling using PyMC in Baseball

    One live session, recorded, 105 minutes. Yours to keep and watch any time.

Chris Fonnesbeck
Your instructor Chris Fonnesbeck

PhD · Biostatistics @ Vanderbilt University Medical Center

Teaches the method the way it is used in the role above. The team page lists everything they teach here.

Also teaches Variational Inference in Sports, MCMC in Practice.

What is included

What is yours when you buy.

  • The full recording, 75 min
  • Yours to keep: watch it any time

Refunds. If you bought it and it is the wrong one for you, write to michael@athlyticz.com and a person will answer.

Questions

The ones that stop a purchase.

Is this too advanced, or too basic, for me?

Built for someone who already writes code in the session's language and wants the method, not the syntax. If the outcome line at the top reads like something you could use next week, it is pitched right. If it reads like a different job, start with the courses on /browse.

What exactly do I get, and for how long?

The full recording, yours to keep: buy once, watch any time. Masterclass subscribers get every live session for a year and can watch every recorded session for as long as they are a member. Everyone else can buy a recording on its own.

Do I need to install anything?

No. The recording plays in the browser.

What if it is not for me?

Twenty minutes on a call before you buy costs nothing, and the call is the fastest way to tell. If you bought it and it is the wrong one for you, email michael@athlyticz.com and a person will answer.

Want more?

Ten live hours of end-to-end project work every month.

The Masterclass is all of it, live and recorded, for $1,899 a year, or $199 a month. Paid by the month, it renews monthly at $199, cancel any time by replying to your receipt.

This session $79

Hierarchical Modeling using PyMC in Baseball. The recording, yours to keep.

Buy now
The Masterclass $1,899 a year, or $199 a month

Every live session this year, and every recording.

Join the Masterclass
Membership $2,999 a year

The whole catalog of courses plus the Masterclass.

Get Membership
$79Buy now