MLB Roster Models

Linear regression and random forest models for historical team run production, with an integer-programming roster comparison.

Try the demo

Results

Model Training CV MAE Test MAE Test RΒ²
Linear regression 0.1219 0.1100 0.9198
Random forest 0.1833 0.1726 0.8062

Training: 1961–1996. Test: 1997–2001. Five forward chronological folds keep every season intact. MAE is runs per team game. The default linear regression is selected using training CV, before test evaluation. The models remain fitted on the 1961–1996 training rows.

Run

Use Python 3.12. Obtain the original project data files Teams.csv, Batting.csv, Master.csv, Salaries.csv, and Appearances.csv, then run:

python -m pip install -r requirements.txt
python train.py --data path/to/data

The exact input hashes are recorded in metrics.json. The accompanying private migration backup retains these CSV snapshots; raw source tables are not reuploaded here. Public sources are Baseball Databank and the Lahman database. Preserve upstream attribution and data terms.

models.joblib contains the trained regressors; test-predictions.npz contains held-out predictions. eligible-players.csv contains historical player inputs and model scores, not current player evaluations. Load joblib files only from trusted sources.

Roster comparison

The optimizer selects nine unique eligible players, one for each batting position including DH, within the archived 2002 salary cap. It uses historical primary positions from 1997–2001 and excludes pitchers. Any eligible nonpitcher may fill DH. Duplicate salary rows are summed per player. Only players with at least 1,000 AB+BB plate appearances over those five years are included.

Player event rates are converted to a team-game scale. The model output is a team-of-identical-batters run-production proxy. The objective sums those proxies; it is not a forecast of actual lineup runs, wins, or contracts available to a particular team. The Space presents exact precomputed solutions for stated budgets.

This is a corrected update of the original coursework project. The original notebook lacked a complete optimization and used inconsistent player scaling; those sections are replaced here.

Downloads last month
-
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Space using iankamar/mlb-roster-models 1