NBA Predictor is a full-stack application for predicting NBA player statistics for upcoming games. It leverages real NBA data, advanced feature engineering, and a machine learning model (multi-output XGBoost regressor) to forecast player performance. The project includes:
- Automated data collection from the NBA API
- Feature engineering for player, matchup, and team statistics
- Model training using historical data
- REST API backend (FastAPI) for serving predictions and NBA data
- Modern frontend (Next.js + React) for user interaction and visualization
- The data collection scripts are in
data_collection/collection.py. - The process uses the
nba_apito fetch:- Game logs for players and teams
- Box scores for each game
- Player and team statistics (season averages, recent games, matchup history)
- Data is saved as CSV files in
data_collection/output/for use in model training.
- Install dependencies (see below).
- Run the data collection script:
python data_collection/collection.py
- You may need to edit the script to specify the season, date range, and output file.
- The script handles NBA API rate limits and saves detailed logs and outputs.
- The training script is in
analytics/train.py. - It loads the processed CSV data from
data_collection/output/. - Feature columns include season averages, recent performance, matchup data, and team stats.
- The model is a multi-output XGBoost regressor, predicting multiple stats (PTS, REB, AST, etc.) at once.
- The script evaluates model performance and saves the trained model as a
.joblibfile.
- Ensure you have collected data as above.
- Run the training script:
python analytics/train.py
- The script will output evaluation metrics and save the model to
analytics/models/.
- The script will output evaluation metrics and save the model to
- Located in
app/backend/ - Built with FastAPI
- Loads the trained model and exposes endpoints for:
- Listing games and players
- Fetching player and team details
- Making predictions for player stats
- Install backend dependencies:
pip install -r app/backend/requirements.txt
- Start the FastAPI server:
uvicorn main:app --reload
- Run this command from the
app/backend/directory. - The API will be available at
http://localhost:8000.
- Run this command from the
- Located in
app/frontend/ - Built with Next.js (React, TypeScript, Tailwind CSS)
- Provides a user-friendly interface to:
- Browse games and players
- View predictions and player stats
- Visualize results with charts
- Install frontend dependencies:
cd app/frontend npm install - Start the development server:
npm run dev
- The app will be available at
http://localhost:3000.
- The app will be available at
- The root
requirements.txtcontains all necessary packages for data collection and model training:pip install -r requirements.txt
- The backend has its own
requirements.txtfor API dependencies:pip install -r app/backend/requirements.txt
- Use
npm installinapp/frontend/to install all frontend dependencies.
- Collect NBA data using the data collection script.
- Train the model with the training script.
- Start the backend API to serve predictions.
- Start the frontend app to interact with the system and visualize predictions.
- Python, FastAPI, pandas, scikit-learn, XGBoost, nba_api, joblib
- React, Next.js, TypeScript, Tailwind CSS, Recharts