Using AI to predict the outcomes of NBA games.
This project aims to streamline the process of predicting NBA game outcomes by focusing on advanced AI prediction models rather than extensive data collection and management. Unlike my previous project, NBA Betting, which aimed to create a comprehensive feature set for predicting NBA games through extensive data collection, this project simplifies the process. While the previous approach benefited from various industry-derived metrics, the cost and complexity of managing the data collection were too high. This project focuses on a core data set, such as play-by-play data, and leverages deep learning and GenAI to predict game outcomes.
The project is currently in the early stages of development, with a basic prediction engine that uses simple models like ridge regression, XGBoost, and a basic MLP. The prediction engine is limited to basic game score predictions and win percentages. The web app provides a simple interface for displaying games for the selected date along with current scores and predictions. Fortunately, this is as complicated as the project should become. The goal is to gradually integrate most pieces of the Database Updater and part of the Games API logic into a single prediction engine. This will allow for a more streamlined process and a more capable prediction engine.
The project is built around a few key components:
database_update_manager.py
: The main module that orchestrates the entire
process.
schedule.py
: Fetches the schedule from the NBA API and updates the database.
pbp.py
: Fetches play-by-play data for games and updates the database.game_states.py
: Parses play-by-play data to generate game states and updates
the
database.prior_states.py
: Determines prior final game states for teams.features.py
: Uses prior final game states to generate features for the
prediction
engine.predictions.py
: Generates predictions for games using the chosen prediction
engine.
games.py
: Fetches game data from the database, manages prediction updating and
data
formatting.api.py
: Defines the API endpoints.games_api.md
: API documentation.start_app.py
: The main entry point for the web app found in the root directory.
app.py
: The main module that defines the Flask app and routes.game_data_processor.py
: Formats game data from the API for the web app.templates/
: Contains the HTML templates for the web app.static/
: Contains the CSS and JavaScript files for the web app.Currently, there are a few basic prediction engines used to predict the outcomes of NBA games. These serve as placeholders for the more advanced DL and GenAI engines that will be implemented in the future. The current engines make pre-game predictions for home and away scores using ML models. These predictions are then used to calculate the win percentage and margin for the home team. Updated (after game start) predictions are based on a combination of the current game score, time remaining, and the pre-game predictions.
The current metrics are based on pre-game predictions for the home and away team scores, along with downstream metrics such as win percentage and margin. These simple predictors currently outperform the baseline predictor.
In the future, a more challenging baseline based on the Vegas spread will be added when the DL and GenAI models are implemented.
Clone the repository to your local machine using the following command:
git clone https://github.com/NBA-Betting/NBA_AI.git
Navigate to the project directory:
cd NBA_AI
Create a virtual environment:
python -m venv venv
Activate the virtual environment:
source venv/bin/activate
Install the required dependencies:
pip install -r requirements.txt
Rename the .env.template
file to .env
:
cp .env.template .env
Open the .env
file in your preferred text editor and set the necessary values:
# .env
# Flask secret key (Optional, Flask will generate one if not set)
# WEB_APP_SECRET_KEY=your_generated_secret_key
# Project root path (Mandatory)
PROJECT_ROOT=/path/to/your/project/root
Replace /path/to/your/project/root
with the actual path to the root directory of your
project on your local machine. You can leave WEB_APP_SECRET_KEY
commented out if you want
Flask to generate it automatically.
By default, the configuration will point to the empty database (data/NBA_AI_BASE.sqlite
). If
you want to use the pre-populated 2023-2024 season data:
v0.1
).NBA_AI_2023_2024.zip
file attached to the release. unzip path/to/NBA_AI_2023_2024.zip -d data
config.yaml
file to point to the extracted database: database:
path: "data/NBA_AI_2023_2024.sqlite" # <<< Set this to point to the database you want to use.
Run the application using the start_app.py
file in the root directory:
python start_app.py
Once the application is running, you can access it by opening your web browser and navigating to:
http://127.0.0.1:5000/
api:
valid_seasons:
- "2023-2024"
- "2024-2025"