Skip to content

This repository leverages machine learning models to predict the outcomes of NBA regular season games and their final scores. By analyzing historical game data, advanced metrics, and team performance trends, the project delivers data-driven insights into game results and scoring patterns

Notifications You must be signed in to change notification settings

ddayto21/NBA-Time-Series-Forecasts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NBA Game Outcome Prediction with Machine Learning

Overview

This project leverages NBA statistics to predict game outcomes using machine learning. The workflow integrates data scraping, feature engineering, and predictive modeling to provide insights into team performance and outcomes. The key focus is on analyzing historical performance, team metrics, and advanced statistics to make accurate predictions.


Key Features

  1. Data Collection: Gather and preprocess historical NBA game data.
  2. Feature Engineering: Create game-specific features, advanced metrics, and rolling averages.
  3. Machine Learning: Train models like Random Forest and Ridge Regression for game outcome prediction.
  4. Evaluation: Assess model performance using classification and regression metrics.

Project Workflow

1. Data Collection

Sources:

Data Extracted:

  • Game Metadata: Date, season, location (home/away).
  • Team Stats: Offensive/defensive ratings, average points, turnovers, and rebounds.
  • Player Stats: Points, assists, rebounds, and player efficiency (PER).
  • Advanced Metrics: Pace, eFG%, TS%, rolling averages, and game context.

2. Feature Engineering

Steps:

  • Preprocessing: Clean data, handle missing values, and normalize features.
  • Derived Features:
    • Home/Away status
    • Days of rest for each team
    • Rolling averages for metrics like scoring trends and defensive efficiency
    • Rivalry indicators and travel fatigue
  • Target Variables:
    • Total Score: Regression target for combined game scores.
    • Winner: Classification target (binary: 1 = Win, 0 = Loss).

3. Machine Learning

Models

  • Classification: Predict game winners using Random Forest, Logistic Regression, or Gradient Boosting.
  • Regression: Predict total game scores using Ridge Regression, XGBoost, or Neural Networks.

Workflow

  1. Split data into training (70%), validation (15%), and testing (15%) sets.
  2. Train models with key features like team stats, home-court advantage, and rolling averages.
  3. Evaluate performance using metrics like Accuracy, MAE, RMSE, Precision, Recall, and F1-Score.

Tools and Technologies

  • Languages: Python
  • Libraries: pandas, BeautifulSoup, sklearn, nba-api
  • Utilities: Selenium for dynamic scraping, Google ChromeDriver
  • Environment: Python 3.10+

How to Run the Project

Prerequisites

  1. Install Python 3.10+.

  2. Install Google Chrome and ChromeDriver.

    brew install --cask chromedriver

Steps

  1. Clone the repository:
git clone htthttps://github.com/ddayto21/NBA-Time-Series-Forecastst.git
cd NBA-Game-Prediction
  1. Set up a virtual environment:
python3.10 -m venv venv
source venv/bin/activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Configure .env file:

Add the ChromeDriver path:

CHROMEDRIVER_PATH=/absolute/path/to/chromedriver
  1. Run the pipeline:
python main.py
  1. Train the model:
python src/training/train.py

Future Enhancements

  1. Add support for asynchronous scraping for faster data retrieval.
  2. Incorporate ensemble models like Random Forest or XGBoost for better predictions.
  3. Create visual dashboards for exploratory data analysis.
  4. Introduce real-time game prediction based on live data.

Contributing

Contributions are welcome! Open an issue or submit a pull request to contribute to this project.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgments

  • Data sourced from Basketball Reference, NBA Stats, and ESPN.
  • Inspired by the rich history of the NBA and the power of data-driven analysis.

About

This repository leverages machine learning models to predict the outcomes of NBA regular season games and their final scores. By analyzing historical game data, advanced metrics, and team performance trends, the project delivers data-driven insights into game results and scoring patterns

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages