This project utilizes a deep learning model to predict the winner of NBA games based on engineered features derived from historical game statistics.
The core of this project is a Keras-based neural network trained on team performance metrics. Instead of using a game's own final stats to predict its outcome (which would be data leakage), we engineer features that represent each team's form and strength before the game begins. This is achieved by calculating 10-game rolling averages for key statistical categories.
The project is structured into a modular pipeline that handles data preprocessing, model training, and prediction.
The project is organized to separate concerns, making it clean and maintainable.
data/
: Contains all the original CSV datasets.notebooks/
:data_analysis.ipynb
: For initial exploratory data analysis (EDA).nba_widget.ipynb
: An interactive Jupyter widget to test the trained model.
src/
: Contains the modular source code.config.py
: Configuration file for paths, features, and model hyperparameters.data_preprocessing.py
: Script for loading data and performing feature engineering (e.g., rolling averages).model.py
: Defines the Keras model architecture.train.py
: The main script to execute the model training pipeline.
predict.py
: A command-line script to make a single prediction using the saved model.requirements.txt
: A list of the project's Python dependencies.nba_prediction_model.keras
: The saved, trained model (generated after running the training script).normalization_stats.json
: Saved mean/std values from the training set for consistent data normalization.
- Python 3.9-3.12
- Git
It is highly recommended to use a virtual environment.
Clone the repository and install the required dependencies:
git clone https://github.com/dimuzzo/NBA-score-prediction.git
cd nba-score-prediction
python -m venv venv
# On Windows
venv\Scripts\activate
# On macOS/Linux
source venv/bin/activate
pip install -r requirements.txt
To train the model, run the train.py
script from the project's root directory:
python -m src.train
This command will load the data, engineer the features, train the model, and save nba_prediction_model.keras
and normalization_stats.json
in the root folder.
You can make predictions in two ways:
A) Via Command Line:
- Modify the
sample_game_data
dictionary inpredict.py
and run the script:python predict.py
B) Via Interactive Widget:
- Launch Jupyter Lab and open the widget notebook:
jupyter lab notebooks/nba_widget.ipynb
- Use directly software like PyCharm.
Use the interactive sliders to input team stats and see the prediction in real-time.
If you want to contribute to the project, feel free to fork the repository and submit a pull request!
Created with passion by dimuzzo