NBA Prediction Model Read Me
This pair of scripts is intended to predict each NBA player's fantasy point total for that day's game for the purpose of building successful lineups in NBA daily fantasy sports.
DFS is a form of fantasy sports where each contest lasts just one day. You are given a certain amount of money to build a lineup with, and then you assemble an eight player team while staying under the salary cap. The player salaries are set by the hosting website every day.
This purpose of these scripts is to bring in a bunch of data to learn from in order to build a prediction model that gives a salary based projection for every available player.
First thing to run every day is the boxScoreScrape.py script, which scrapes basketball-reference.com for every box score of each game played in the previous day. This is the core data that our models rely on. It saves off every individual player box score and every team box score, generating a ton of data.
The getDailyData.py script does the following:
- Retrieves the day's player salaries for each website (DraftKings and FanDuel) and saves off these salaries every day so we can learn from salary history
- Retrieves the betting lines for each game (the over/under betting total generated by sports book is valuable for getting an idea of what games will score more or less points)
- Retrieves player minutes played projections from three different websites
- Loops through each team and sees how they have performed against each individual position defensively so far that season
- Projects each team's fantasy total for the night using a linear model that is trained to project team output based on Vegas total and opponent's defensive rating
- Takes every player and simulates an output based on their season box scores to date, this can identify underpriced players by comparing their simulated average score to their salary for the day
After that we have everything we need to build and run the model for that day's projections. The runModel.py script does this.
- Updates the betting lines and minutes projections to account for any changes that may have occurred up to that point in the day
- Uses all season data to train a model to project fantasy point output based on team projected total, player stats, and opponent defensive rating
- Combines all relevant informaton into a CSV file that is formatted with a macro and then turned into an XLSX file.
All three scripts and an example of the final product (the .xlsx file) are on this Github repository.