MLB Total Runs Estimation Tool
May 23, 2025.
Over the last few months, I built an end-to-end predictive analytics system that forecasts Major League Baseball game totals (the expected combined runs scored) by combining multi-year historical data with supervised machine learning. The objective was to produce a calibrated run projection for each matchup and evaluate that projection against the market’s consensus number as an independent benchmark.
The hardest part of the project was not the model itself, but assembling a clean, usable dataset. I scraped and reconstructed roughly five years of detailed game data (2021 through the current season) from the MLB Stats API and related sources: schedules, box scores, pitcher-level lines, weather, and venue context, game by game. Early attempts failed in predictable ways. Pulling an entire multi-year schedule in one request routinely timed out or returned 503 errors. Hitting the API too aggressively caused incomplete downloads and silent gaps. Parsing was fragile: innings pitched arrived as baseball strings like “5.1” rather than decimals; starter versus bullpen splits had to be derived carefully from pitcher sequencing; spring training and exhibition games contaminated the sample until they were filtered out. Only after chunking requests by year, adding retries and rate limiting, validating completeness, and writing deterministic parsers did the historical archive become complete enough to train on.
With that foundation, feature engineering became the core of the model. For each team, I computed season-to-date offensive rates that are shifted so no post-game information leaks into the prediction, plus platoon-split versions conditioned on the opposing starter’s handedness. Pitching features include Fielding Independent Pitching (FIP) for the starter and bullpen, along with a three-day bullpen workload measure. Temperature, wind, and a lagged venue run factor capture environmental scoring context without using same-season leakage.
I framed the problem as regression, predicting total runs, after simpler approaches underperformed: recent-run averages, linear models, and classifiers that were less informative about scoring environment. A gradient-boosted regressor (XGBoost) handled nonlinear interactions more effectively while remaining interpretable enough to inspect feature importance.
Evaluation was deliberately skeptical. Vegas odds are historically used in the analytics community as a benchmark. Walk-forward and monthly-retrain tests, then scoring future months against historical consensus totals produced the best results. The model was able to predict the direction of the total 55% of the time when the back test was performed using the held out data.
Ultimately, this project reinforced that effective predictive analytics depends as much on disciplined data engineering and evaluation as it does on model selection. Building the system required me to integrate unreliable data sources, prevent information leakage, engineer features, and test performance under realistic time-based conditions. More importantly, it taught me to treat a model’s output as evidence rather than certainty. The final product is not simply a run-prediction model, but a repeatable framework for converting raw, fragmented information into carefully validated and actionable forecasts.