Part 1 of the Exploratory Data Analysis can be found here : https://rpubs.com/stanspwan/275198


In this Part 2 , I try the prophet forecasting package from facebook on the speeding violations data set.


Plotting the 2014-2016 Chicago Speed Cam violations time series chart

hchart(tseries, name = "test") %>%
  hc_add_theme(hc_theme_economist()) %>%
  hc_credits(enabled = TRUE, text = "Data Source : Chicago Police Department", style = list(fontSize = "13px")) %>%
  hc_title(text = "Times Series plot of speed camera violations in Chicago 2014-2016") %>%
  hc_legend(enabled = TRUE)

Forecasting (Using prophet package from facebook)

1. Fit our model

my_model <- prophet(df)
## Initial log joint probability = -4.28681
## Optimization terminated normally: 
##   Convergence detected: relative gradient magnitude is below tolerance
# creating time stamps for two years
future <- make_future_dataframe(my_model, periods = 365 * 2)

#Quick sneak peek
head(future)
##           ds
## 1 2014-07-01
## 2 2014-07-02
## 3 2014-07-03
## 4 2014-07-04
## 5 2014-07-05
## 6 2014-07-06
tail(future)
##              ds
## 1640 2018-12-26
## 1641 2018-12-27
## 1642 2018-12-28
## 1643 2018-12-29
## 1644 2018-12-30
## 1645 2018-12-31


## 2. Forecast prediction

forecast <- predict(my_model, future)

tail(forecast[c('ds', 'yhat', 'yhat_lower', 'yhat_upper')])
##              ds     yhat yhat_lower yhat_upper
## 1640 2018-12-26 4.627034   4.412295   4.841228
## 1641 2018-12-27 4.618168   4.406873   4.835586
## 1642 2018-12-28 4.578050   4.366928   4.788702
## 1643 2018-12-29 4.155719   3.934655   4.376804
## 1644 2018-12-30 4.151697   3.932252   4.357084
## 1645 2018-12-31 4.585387   4.370674   4.786704


## 3. Plotting the forecast

plot(my_model, forecast)


# Weekly, Monthly and Annual breakdown
prophet_plot_components(my_model, forecast)


Disclaimer/Note: This may not be the most scientific forecasting, I am just familiarizing myself with Facebook’s Prophet forecasting package and trying to use it.Any suggestions are welcome.

Link to part 1 : https://rpubs.com/stanspwan/275198