Practice · Baseball · Simulated for practice
Six thousand invented pitches, 1,500 of each type, with release speed. A clean dataset for the full model-checking loop: fit, simulate, compare, fix.
pitch_typestringrelease_speednumber · mphSimulated for practice. Simulated for practice by AthlyticZ (agents/sim_data.py, seed 20261109). License CC BY 4.0. Generated from a documented model with realistic distributions; every name is invented.
Edit the code and press Run to recompute it in your browser.
Edit me: Move the prior sd, or change first_n to 200 and run: the data overwhelms the prior.
Data: Pitch speeds by type (pitches_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 Pyodide; nothing you type leaves the page.
import pandas as pd
pitches = pd.read_csv("data/pitches_2026.csv")
pitches.groupby("pitch_type").release_speed.describe().round(1)
Try each before opening the hint; open the worked solution only after your own attempt.
Report the mean and spread of release speed for each pitch type, and the gap between the fastest and slowest type.
One groupby with agg for mean and std; the gap is the difference of the extremes of the means.
import pandas as pd
p = pd.read_csv("data/pitches_2026.csv")
s = p.groupby("pitch_type").release_speed.agg(["mean", "std"]).round(2).sort_values("mean")
print(s.to_string())
print("gap between fastest and slowest type:", round(s["mean"].max() - s["mean"].min(), 1), "mph")
Output, from running this code on the dataset when the page was built
mean std pitch_type CU 79.43 2.79 CH 85.02 2.47 SL 85.58 2.40 FF 93.97 1.93 gap between fastest and slowest type: 14.5 mph
Using only the first 20 pitches of each type, compute the posterior for each type's mean speed under a normal prior centered at 88 mph with sd 2. How far is each posterior from the mean of all 1,500?
Normal prior, normal data with the sample sd plugged in: the posterior precision is the sum of the precisions, and the posterior mean is the precision-weighted average.
import numpy as np
import pandas as pd
p = pd.read_csv("data/pitches_2026.csv")
truth = p.groupby("pitch_type").release_speed.mean()
first = p.groupby("pitch_type").head(20).groupby("pitch_type").release_speed.agg(["mean", "std", "size"])
prec = 1 / 2.0**2 + first["size"] / first["std"] ** 2
post = (88 / 2.0**2 + first["size"] * first["mean"] / first["std"] ** 2) / prec
print(pd.DataFrame({"posterior": post, "sd": 1 / np.sqrt(prec), "all 1,500": truth,
"miss": post - truth}).round(2).to_string())
Output, from running this code on the dataset when the page was built
posterior sd all 1,500 miss pitch_type CH 85.87 0.52 85.02 0.85 CU 80.45 0.80 79.43 1.03 FF 94.17 0.35 93.97 0.20 SL 86.57 0.33 85.58 1.00
Fit a single normal to all 6,000 speeds, ignoring pitch type, and run a posterior predictive check: simulate 200 replicated datasets and compare the share of pitches between 82 and 88 mph with the real share. What does the check say, and what fixes it?
The single normal puts most of its mass in the middle; the real data has a valley there between breaking balls and fastballs. A mixture by pitch type is the fix; check it the same way.
import numpy as np
import pandas as pd
p = pd.read_csv("data/pitches_2026.csv")
v = p.release_speed.to_numpy()
stat = lambda a: np.mean((a > 82) & (a < 88))
rng = np.random.default_rng(5)
single = [stat(rng.normal(v.mean(), v.std(), v.size)) for _ in range(200)]
g = p.groupby("pitch_type").release_speed.agg(["mean", "std", "size"])
mixture = [stat(np.concatenate([rng.normal(r["mean"], r["std"], int(r["size"])) for _, r in g.iterrows()])) for _ in range(200)]
print(f"real share between 82 and 88 mph {stat(v):.3f}")
print(f"single normal, 90% of replicates {np.percentile(single, 5):.3f} to {np.percentile(single, 95):.3f}")
print(f"mixture by type, 90% of replicates {np.percentile(mixture, 5):.3f} to {np.percentile(mixture, 95):.3f}")
Output, from running this code on the dataset when the page was built
real share between 82 and 88 mph 0.431 single normal, 90% of replicates 0.382 to 0.405 mixture by type, 90% of replicates 0.426 to 0.441
Give an agent the hard question's output and ask it to choose between the two models and justify the choice in two sentences. Then ask it to propose one more test statistic that would catch a different failure of the single normal, and run it yourself before accepting the answer.
MCMC in Practice. Every dataset in the practice library names its session the same way.
A short welcome note, a few session picks over two weeks, then only the updates you signed up for. Reply stop any time.
Loading the calendar.
The calendar did not load here. Open it on Calendly.
Confirmed
Calendly has sent the invitation to your inbox, with the link for the call. Michael will see you then.
We've teamed up with AthlyticZ to supercharge how we use data science and statistics to impact our sports. More clarity in the numbers means bigger results for our athletes.
AthlyticZ has completely transformed the learning approach to data science through the use of sports-based problems. The instructors are the best of the best, and the practical projects have immediate impact to students.
The sports industry moves fast. Managing the pace of evolving technology, data, and AI isn't optional - it's imperative. Our Analytics team was looking for a partner to meet us where we are, to help us in the continued investment of our people and capabilities without pulling us away from the work that matters. AthlyticZ delivers exactly that: a structured, practitioner-led platform that fits how modern sports analytics groups actually operate.