Instructions to use iankamar/mlb-roster-models with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Scikit-learn
How to use iankamar/mlb-roster-models with Scikit-learn:
from huggingface_hub import hf_hub_download import joblib model = joblib.load( hf_hub_download("iankamar/mlb-roster-models", "sklearn_model.joblib") ) # only load pickle files from sources you trust # read more about it here https://skops.readthedocs.io/en/stable/persistence.html - Notebooks
- Google Colab
- Kaggle
MLB Roster Models
Linear regression and random forest models for historical team run production, with an integer-programming roster comparison.
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
- -