library(rpart)
library(visNetwork)
library(sparkline)
file.exists("DodgersData.csv")
## [1] TRUE
# Basic classification tree
res <- rpart(attend~., data=read.csv("DodgersData.csv"))
visTree(res, main = "Dodgers Attendance Tree", width = "100%")
#Interpret
Based on the visual tree, we will be able to interpret the attendance for a baseball game based on different criteria. For example, we can determine that about 53,145 people will attend the game if they decide to give out bobble heads. We can also determine from this tree that if the Dodgers do not give out bobble heads, play versus the Astros, and play on Monday then they will have a lower attendance estimated at 32,628 people.
#Extra Tree! :)
res <- rpart(day_of_week~., data=read.csv("DodgersData.csv"))
visTree(res, edgesFontSize = 14, nodesFontSize = 16, width = "100%")