Parsing NBA Statistics
In this project, we parse nba data, load into a database and calculate some statistics from our db. Reading in the data from our normalized database we also predict the result of a match between two opponents. Data is made accesible via a command line interface.
As as defined below:
- Parse NBA statistics provided in the archive files
- Dump the statistics into a MySQL database in a normalized format
- Create a user facing functionality to retrieve the following data points:
- The best player in terms of productivity for each week of the selected season
- Prediction of a match result between two teams
- Exterior command line interface
Project Main Folder
|--start_app.py #runs the main app on the command line
|--player_efficiency.py #contains functions run player efficiency by week
|
|--data
| |--init.py #module import
| |--dbfile #will hold the database when initiated
| |--archive.zip #zipped file of data to process
| |--create_db.py #python file with functions for creating a db instance
| |--process_data.py #python file for data processing & cleaning
| |--process_dataframes.py #python file for additional data processing & cleaning
|
|--models
| |--init.py #module import
| |--classifier.pkl.csv #will hold the classifier of the ml model
| |--train_classifier.py #python script to train model on data
|
|--README.md
|--requirements.txt
Environment Optional: If you plan to use a virtual environment. In the terminal run the following commands:
- python3 -m venv environment-name
- Follow up by running:
- Windows: run venv\Scripts\activate || On Linux/Mac:source environment-name/bin/activate
- python3 -m pip install --upgrade pip
- pip3 install -r requirements.txt
- To deactivate: deactivate
Compulsory Setup
-
Run the following commands in the project's root directory to set up the database and classifier model.
-
To run ETL pipeline that cleans data and stores in database
python3 data/process_data.py data/archive.zip data/mydb.db -
To run ML pipeline that trains classifier and saves to disk
python3 models/train_classifier.py data/mydb.db models/classifier.pkl
-
-
Run the following command in the app's directory to run the terminal app.
python3 start.py data/mydb.db models/classifier.pkl
The project can be separted into three sections, each with their contributions to the application.
- ETL Pipeline
A Python script,
process_data.pyandcreate_db.py, that runs a data cleaning pipeline that:
- Create the db with
create_db.py - Loads the archive datasets
- Merges the two datasets
- Cleans the data
- Stores it in a SQLite database
- ML Pipeline
In a Python script,
train_classifier.py, that runs a machine learning pipeline that:
- Loads data from the SQLite database
- Splits the dataset into training and test sets
- Builds a text processing and machine learning pipeline
- Trains and tunes a model
- Exports the final model as a pickle file
- ML Pipeline
In a Python script,
player_efficiency.py, calculates stats from the database: Productivity is defined as: Efficiency in Basketball Wiki (PTS + REB + AST + STL + BLK − (Missed_FG + Missed_FT + TO)) / GP
- Calculates the player productivity statistics via an sqlalchemy orm
- Prints the db to the command line
- Exports the final model as a pickle file
- Command Line Application A small interactive command line application that enables you in getting stats and data from the Database