Machine learning model to predict NBA games trained on scraped data.
- Game Winner Prediction: Predicts which team will win NBA games
- Comprehensive Statistics: Uses extensive team statistics including traditional and advanced metrics
- Web Scraping Pipeline: Automated data collection using Playwright and BeautifulSoup
- Ridge Classifier Model: Robust machine learning approach for binary classification
- Historical Data: Training on NBA game data with team performance metrics
- Python: Core programming language
- scikit-learn: Ridge Classifier implementation and model evaluation
- pandas: Data manipulation and analysis
- numpy: Numerical computing
- BeautifulSoup (bs4): HTML parsing for web scraping
- Playwright: Web browser automation for data collection
- Accuracy: 63% on test data
- Algorithm: Ridge Classifier
- Prediction Type: Binary classification (Win/Loss)
The model uses a comprehensive set of team statistics including:
Traditional Stats: Minutes played (mp), field goals (fg, fga, fg%), 3-pointers (3p, 3pa, 3p%), free throws (ft, fta, ft%), rebounds (orb, drb, trb), assists (ast), steals (stl), blocks (blk), turnovers (tov), personal fouls (pf), points (pts), plus/minus (+/-)
Advanced Stats: True shooting percentage (ts%), effective field goal percentage (efg%), 3-point attempt rate (3par), free throw rate (ftr), rebound percentages (orb%, drb%, trb%), assist percentage (ast%), steal percentage (stl%), block percentage (blk%), turnover percentage (tov%), usage percentage (usg%), offensive rating (ortg), defensive rating (drtg)
Team Context: Home/away status, season information, game dates
Opponent Stats: Complete mirror of all above statistics for opposing teams
- Python 3.7 or higher
- scikit-learn
- pandas
- numpy
- bs4
- playwright
- Clone the repository:
git clone https://github.com/mlicamele/nba-prediction.git
cd nba-prediction- Install required packages:
pip install scikit-learn pandas numpy beautifulsoup4 playwright- Install Playwright browsers:
playwright installnba-prediction/
├── data/
│ ├── scores/ # Game score data
│ └── standings/ # Team standings data
├── get_data.ipynb # Data collection notebook
├── parse_data.ipynb # Data processing notebook
├── predict.ipynb # Model training and prediction notebook
├── nba_games.csv # Processed game data
├── .gitattributes # Git LFS configuration
├── .gitignore # Git ignore file
└── README.md
The project is organized as Jupyter notebooks for easy exploration and execution:
Open and run get_data.ipynb to scrape the latest NBA data:
jupyter notebook get_data.ipynbProcess and clean the scraped data using parse_data.ipynb:
jupyter notebook parse_data.ipynbTrain the Ridge Classifier and make predictions with predict.ipynb:
jupyter notebook predict.ipynbThe project uses web scraping to collect NBA statistics:
- Playwright: Handles dynamic web content and browser automation
- BeautifulSoup: Parses HTML content to extract statistical data
- Data Sources: NBA team statistics, game scores, and standings
- Type: Linear classifier with L2 regularization
- Advantages: Handles multicollinearity well, robust to overfitting
- Input: Team statistics for both teams in a matchup
- Output: Binary prediction (0 = away team wins, 1 = home team wins)
The model incorporates:
- Team performance statistics
- Maximum player statistics per game
- Opponent statistics (complete statistical profile of opposing team)
- Home/away indicators
- Temporal features (season, date)
- get_data.ipynb: Web scraping implementation using Playwright and BeautifulSoup
- parse_data.ipynb: Data cleaning, processing, and feature engineering
- predict.ipynb: Model training, evaluation, and prediction generation
- nba_games.csv: Final processed dataset with all features
- data/scores/: Raw game score data from scraping
- data/standings/: Team standings and ranking data