Welcome to the Player Performance Prediction project! This repository contains a complete workflow for predicting baseball player statistics such as Wins Above Replacement (WAR), Hits, Home Runs (HR), and Stolen Bases (SB) using historical data.
The project includes:
- Data preprocessing and analysis
- Model training and evaluation
- A Flask web application for interactive predictions
Table of Contents
Overview
The objective of this project is to forecast future baseball player performance metrics using machine learning models. A Flask web app provides an intuitive interface to select players and view predictions into the future.
Key features:
- Analysis of historical player performance data
- Predictions using multiple linear regression models
- Interactive web-based interface
Project Files
- notebooks/
Mini_Project_2.ipynb: The main notebook containing data exploration, modeling, and Flask app setup.
- data/
Player_Offense_by_Season.xlsx: The dataset used for training and testing.
- models/
WAR_model.pkl, H_model.pkl, HR_model.pkl, SB_model.pkl: Pre-trained models for forecasting.
- app/
app.py: Flask application code.
templates/: HTML templates for the Flask app.
- README.md: This documentation.
Data Analysis
The dataset includes player statistics across seasons, such as:
- WAR: Wins Above Replacement
- Hits, Home Runs (HR), Stolen Bases (SB)
- Additional performance metrics: Plate Appearances (PA), At Bats (AB), Games Played (G), Slugging Percentage (SLG), On-base Percentage (OBP)
Insights
- Linear regression was used to model relationships between player statistics and future performance.
- Exploratory analysis revealed trends and correlations among variables.
Modeling
Four machine learning models were trained to predict:
- WAR
- Hits
- Home Runs (HR)
- Stolen Bases (SB)
- WAR Model: R²: 0.8774, MSE: 0.6255
- Hits Model: R²: 0.9768, MSE: 57.0402
- HR Model: R²: 0.9013, MSE: 18.2825
- SB Model: R²: 0.4450, MSE: 69.7393
Web Application
A Flask web application provides:
- Player Selection: Users can select a player from a dropdown.
- Future Forecasts: Predictions for up to 5 future seasons.
- Interactive Interface: Results displayed in a user-friendly table format.
Routes
/: Home page with player selection.
/predict: Displays forecast results.
Installation
Prerequisites
Ensure the following are installed:
- Python 3.x
- Flask
- Pandas
- Scikit-learn
Steps
- Clone the repository:
git clone https://github.com/chadb12/player-performance-prediction.git
cd player-performance-prediction
- Install dependencies:
pip install -r requirements.txt
- Run the Flask application:
- Open the app in your browser:
Usage
- Launch the Flask app.
- Select a player from the dropdown menu.
- View forecasts for WAR, Hits, HR, and SB for the next few seasons.
Future Work
- Incorporate additional metrics for richer predictions.
- Add clustering techniques to group players by performance.
- Enhance the web interface for better user experience.
- Transition to a production-grade deployment using services like AWS Elastic Beanstalk.
Acknowledgments
- Data sourced from StatHead.com