Python and R scripts that automatically detect statistical anomalies within the latest game logs of individual players
What it does:
- Scrape all available past game logs of every NBA player in the current season from ESPN.
- Store them as individual csv files.
- Scrape latest game logs and update local csv files accordingly.
- Detect any statistical anomalies in the latest finished games in the updated csv files.
To run the scripts, you need to have Python 2.7 and R installed. I also recommend installing RStudio as IDE for R. You need to install two additional Python packages: bs4 and urllib2.
How to:
- Download the zip file containing all scripts and unzip the directory to your computer.
- Create two new directories, "csv files" and "logs" within the local directory to store csv files and daily anomaly logs respectively later.
- Open helper.py, change PATH and TEST_PATH (an optional directory for you to test codes) according to your own settings; do the same with csv_path and log_path in detector.R.
- Open the command line, change the working directory to the directory and enter "python main.py", which runs the Python codes in main.py (Or do the equivalent in Linux/OSX environments).
- Open RStudio, and call function source(), the single parameter being the path to detector.R with quotation marks, in the console, which allows you to call functions in detector.R.
- Call function detect_all(), which will detect and print out any anomalies, and store the results in a txt file in "logs".
- Take a look at the logs to discover the anomalies of the day!