Teaching Probability Through Soccer: Built With Claude Code

A statistics site for middle and high school students, built around the math pro analysts actually use.


Teaching Probability Through Soccer: Built With Claude Code

A statistics site for middle and high school students, built around the math pro analysts actually use.

What’s the probability they have a flavor you like.

Middle and high school statistics runs on coin flips and bags of marbles. Few kids walk out of those units wondering when they will get to apply the binomial distribution to a real question they care about.

I built learnsportsstats.com for the kids who would care if you gave them a reason. The site teaches expected goals, Elo ratings, Bayesian updating, the Poisson distribution, and Monte Carlo simulation through soccer. Premier League clubs pay analysts six figures to apply these methods to match prediction, player valuation, and tactical planning. A student can follow the same math if the example is right.

I built it with Claude Code.

Why soccer first

Soccer scores low and resolves cleanly. A typical match produces between zero and six goals. That sparse outcome distribution makes the math easier to teach. Students can see every event, count the shots that became goals and the ones that did not, and match real match results against a predicted distribution without drowning in possessions, downs, or innings.

Global familiarity matters too. The site has to work for a kid in Maryland and a kid in Lagos. Soccer covers more of the second case than baseball ever will.

The five concepts

Each topic page on the site builds the math from a shot or a season that the student can verify against real data.

Expected goals (xG) assigns a probability to every shot based on distance, angle, body part, and defensive pressure. A penalty kick scores roughly 0.76. From thirty-five yards out with defenders in front, the probability drops below 0.02. Summing those probabilities across a match gives a quality-adjusted view of who deserved to win, regardless of the scoreboard. The page walks students through training a tiny logistic regression on a handful of shot features.

Elo ratings treat every match as a transaction between two team strengths. Beat a stronger opponent and your rating climbs by a larger increment. Losses to weaker sides cost more points as the strength gap widens. The system started in chess. The page derives the update equation step by step and lets students replay last season’s Premier League table to see how a few upsets shift the standings.

Bayesian updating answers a question middle schoolers actually ask the moment they see it: how should I revise my belief about a team after one more match? The page starts with a prior, applies a likelihood from observed goals, and outputs a posterior. The worked example uses a relegation candidate that wins three in a row. Students see how strong evidence shifts a weak prior. A confident prior, by contrast, resists a single surprising result without much movement.

The Poisson distribution models goal counts. Given a team’s average goals per match, Poisson predicts the probability of zero, one, two, or three goals in the next match. The page derives the formula, plots the distribution against actual season data, and asks students to identify where the model misses. Low-scoring matches show up more often than raw Poisson predicts, a known issue formalized by Dixon and Coles in 1997.

Monte Carlo simulation runs the season ten thousand times. Each simulation samples goals from the Poisson distribution for each team in each match, accumulates points, and ranks the table. The output is a probability distribution over final standings. Students see why the right answer to “will Liverpool win the league” is never a single number.

What Claude Code shaped

Building this without an AI coding agent would have taken months I do not have. With Claude Code, the work was compressed into a structure I could actually maintain.

For each topic, I started with a specification in a markdown file. The spec described the math, the worked example, the interactive control, and the visualization. Claude Code generated the React component, the LaTeX rendering, the D3 chart, and the explanatory copy from that spec. I reviewed, corrected, and re-prompted. The xG page took an afternoon. The Monte Carlo simulator took a weekend, mostly because the visualization needed three rounds of refinement before the histogram conveyed what I wanted.

Claude Code did not handle the teaching order. Which concept comes before which, what to assume the student already knows, how much algebra to show, and how much to hide, came from me. So did the choice of worked examples. A kid stays with a page when the example is one they can verify on their own.

Claude Code replaced the second half of every page. Implementation, styling, responsive layout, equation rendering, chart legends, and tooltip copy. That used to take me longer than the math itself.

What is next

The site launches with soccer. Basketball comes next, because the math overlaps directly. Shot quality maps to expected points per shot, Elo transfers without modification, and Poisson approximates possessions reasonably well over a full game. Baseball follows, where Bayesian inference has the longest applied history in sports through sabermetrics. American football comes last on the list, because the data is messier and the worked examples are harder for a student to verify by hand.

The audience is middle and high school students who already follow a sport and want the math to match what they already see. The site assumes basic algebra. Students need no calculus and no prior statistics coursework. A student who finishes the soccer section understands more applied probability than I did at the end of my first college statistics course.

Why I built this

The math in professional sports analytics is the same math middle and high school students are being taught. Kids who follow a sport rarely run into that overlap in school. The site shows it through soccer, and every claim on every page checks against real match data.

The site is live at learnsportsstats.com. Feedback welcome from teachers, coaches, parents, and the students themselves.

If you run a small sports league with stats already collected, reach out. I can integrate league-specific data so the worked examples use teams the students actually follow. A county high school soccer table will pull a kid in that county further into the math than the Premier League can.

By Joshua McDonald on May 19, 2026.

Canonical link

Exported from Medium on August 26, 2026.