This project was created to build a machine learning model to predict Australian Football League (AFL) attendances using historical data.
Two articles have been posted to Medium:
- Using Data To Determine Which AFL Fans Jump On The Bandwagon
- Building a Linear Regression Model in R to Predict AFL Crowds
Three sources of data were used in the project:
- AFL Tables was used as the primary source of information. This is no doubt the go to for anyone looking at doing AFL analysis
- Australian Sports Betting was used to get betting data for matches from the 2013 season
- Australian Bureau of Meteorology was used for climat data (rain and temperature). Part of the scraper for BOM data was taken from James Day's fitzRoy R package. Big thanks to him.
- rvest
- httr
- dplyr
- stringr
- tidyr
- lubridate
- tidyverse
- car
- MASS
- readxl
Functions have been created to colect both sources of data:
- afl_scraper.R goes and scrapes eihter a single season, or a range of seasons.
- return_betting_data.R downloads the betting data xlsx file and does some preprocessing steps
- get_bom_data.R extracts rain and temperature data and fills in missing values. Missing rain figures are averaged out with the next available reading, while missing temperatures are given that months averag min and max temp.
Then to scrape and save the files to csv, run src/get_afl_data.R.
If existing data in this repo is enough, simply run src/preprocessing.R to go thorough the preprocessing steps to get the data ready for the analysis in the Medium posts.