Introduction to Prophet in R

Nan Hanagud

6/29/2017

Agenda

Prophet

Capabilities

The Model

y(t) = g(t) + s(t) + h(t) + ε

g(t): growth function : Logistic growth model with non-constant carrying capacity with changepoints or linear growth model with changepoints. Changepoints are used to model changing rates of growth.

s(t): seasonality (weekly or yearly)

h(t): holidays

ε: error

Data for this demo

Data Format

##        ds                   y        
##  Min.   :2015-01-01   Min.   :    0  
##  1st Qu.:2015-08-07   1st Qu.:    2  
##  Median :2016-03-13   Median : 9839  
##  Mean   :2016-03-13   Mean   : 7305  
##  3rd Qu.:2016-10-18   3rd Qu.:10925  
##  Max.   :2017-05-25   Max.   :14694

Data Graph

Training Set

Create a training set - let’s use 2 years so we can let it detect growth/seasonality.

df_train<- df[df$ds < as.Date("2017-01-01"),]
summary(df_train)
##        ds                   y        
##  Min.   :2015-01-01   Min.   :    0  
##  1st Qu.:2015-07-02   1st Qu.:    2  
##  Median :2016-01-01   Median :10015  
##  Mean   :2016-01-01   Mean   : 7384  
##  3rd Qu.:2016-07-01   3rd Qu.:11023  
##  Max.   :2016-12-31   Max.   :14694

Forecast Assumptions

Forecast - 30 Days Forward

30 Days forward

m <- prophet(df_train)
future <- make_future_dataframe(m, periods=30) 
forecast <- predict(m,future)

Forecast - 90 Days Forward

90 Days forward

m <- prophet(df_train)
future <- make_future_dataframe(m, periods=90) 
forecast <- predict(m,future)