Building an MLB Home Run Prediction Model (260k+ Historical Records) – Looking for Feedback
I've been teaching myself sports analytics and machine learning by building an MLB home run prediction model from scratch in Python and MySQL.
Current version:
- ~260,000 historical batter-game records
- XGBoost classifier
- Daily automated pipeline
- Predicts probability of a player hitting a home run in today's games
Current features include:
Hitter Features
- HR last 3, 5, 10, 15, and 30 games
- Hits last 3, 5, 10, 15, and 30 games
- AVG, OBP, SLG, OPS rolling windows
- HR rates over multiple windows
Pitcher Features
- HR allowed
- HR/9
- ERA
- WHIP
- K/9
Using rolling windows:
- Last 3
- Last 5
- Last 10
- Last 15
- Last 30
Matchup Features
- Batter vs Pitcher history (BvP)
- Plate appearances
- Hits
- Home runs
- Strikeouts
- Walks
Context Features
- Home/Away
- Batting order
- Probable starting pitcher
- Confirmed daily lineups
One challenge I've run into is balancing recent performance against small-sample-size BvP data. Early versions of the model heavily overvalued BvP, so I've been reducing its influence and letting recent HR trends drive more of the prediction.
A few questions for anyone who has worked on similar baseball models:
- What features gave you the biggest improvement when predicting home runs?
- Did park factors or weather meaningfully improve results?
- Have you found Statcast metrics (barrel %, hard-hit %, launch angle, xSLG, etc.) to outperform traditional rolling stats?
- Would you treat HR prediction as a pure classification problem, or try to predict expected HR probability another way?
This project started as a learning exercise, but it's turning into a pretty fun sports analytics project. Any feedback is appreciated.
u/Head_Vermicelli_6032 — 13 days ago