Welcome to my portfolio showcasing my data analytics and cloud engineering projects.
The MLB Wins Predictor is a machine learning project that forecasts the number of wins a Major League Baseball (MLB) team will achieve in a season based on key performance metrics. This project utilizes a Keras neural network model trained on historical team data, with a FastAPI backend serving real-time predictions via a RESTful API.
/predict endpoint.mlb-wins-predictor/
โ
โโโ app.py # FastAPI application for serving predictions
โโโ mlb_wins_model.h5 # Trained Keras model (HDF5 format)
โโโ scaler.pkl # StandardScaler for data normalization
โโโ pitching_batting_combined_df.csv # Combined dataset for model training
โโโ README.md # Project documentation
โโโ requirements.txt # Python dependencies
โโโ tuner_results/ # Keras Tuner results for hyperparameter tuning
pitching_batting_combined_df.csv contains various performance metrics (batting and pitching).W).WAR, RS, SO, SV, ER, R, SH, GB, ERA, BBgit clone https://github.com/ChadB12/mlbwinspredictor.git
cd mlbwinspredictor
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
Place the following files in the root directory:
mlb_wins_model.h5: Trained Keras model.scaler.pkl: StandardScaler for input data normalization.uvicorn app:app --host 0.0.0.0 --port 8000
The API should now be running at http://0.0.0.0:8000.
/predictPOSTapplication/jsonRequest Format:
{
"data": [[45, 850, 1300, 45, 520, 650, 30, 1400, 3.50, 450]]
}
Example Response:
{
"predictions": [90.5]
}
curl:curl -X 'POST' \
'http://your_server_ip:8000/predict' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"data": [[45, 850, 1300, 45, 520, 650, 30, 1400, 3.50, 450]]
}'
Typical input values for the model based on an above average MLB teamโs stats:
| Feature | Description | Example Value |
|---|---|---|
| WAR | Wins Above Replacement | 45 |
| RS | Runs Scored | 850 |
| SO | Strikeouts by pitchers | 1300 |
| SV | Saves | 45 |
| ER | Earned Runs | 520 |
| R | Runs allowed by pitchers | 650 |
| SH | Sacrifice Hits | 30 |
| GB | Ground Balls | 1400 |
| ERA | Earned Run Average | 3.50 |
| BB | Walks allowed by pitchers | 450 |
Go to Docs: Open the Swagger UI to test the API via a user-friendly interface:
http://18.219.97.159:8000/docs
Interactive API Documentation: Use the Swagger interface to send POST requests and view responses.
The dataset used for training the model includes a combination of pitching and batting statistics. The dataset can be found in the following path within the repository: