Nan Hanagud
6/29/2017
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
## 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
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
m <- prophet(df_train) future <- make_future_dataframe(m, periods=30) forecast <- predict(m,future)
m <- prophet(df_train) future <- make_future_dataframe(m, periods=90) forecast <- predict(m,future)
prophet_plot_components(m, forecast)
Control fit of model via changepoints
prophet(df_train, changepoint.prior.scale = 0.1)
plot(m, forecast)
Holidays can be incorporated into the series with a window around it to indicate change of behavior in that time frame
EoYholiday <-data.frame(
holiday='thanksmas',
ds=as.Date(c('2015-11-26','2015-12-25','2016-11-24','2016-12-25')),
lower_window=1, upper_window=2)
SoYHoliday<-data.frame(
holiday='memind',
ds=as.Date(c('2015-1-1','2015-05-25','2015-07-04','2016-1-1','2016-05-30','2016-07-04', '2017-1-1')),
lower_window=1, upper_window=0)
holidays <- bind_rows(EoYholiday,SoYHoliday)
m <- prophet(df_train, holidays=holidays) forecast <- predict(m,future) prophet_plot_components(m, forecast)
I may have made it worse ¯\(ツ)/¯
prophet(df = df, growth = “linear”, changepoints = NULL, n.changepoints = 25, yearly.seasonality = TRUE, weekly.seasonality = TRUE, holidays = NULL, seasonality.prior.scale = 10, changepoint.prior.scale = 0.05, holidays.prior.scale = 10, mcmc.samples = 0, interval.width = 0.8, uncertainty.samples = 1000, fit = TRUE)
Capacities a low or declining capacity can be used to adjust the forecast downward or even to produce negative growt e.g. df$cap <- 100 can be specified for every row and is therefore non-constant.
Changepoints - Known dates of changepoints can be directly specified, such as for example a new product model introduction.
Holidays and seasonality - Holiday dates and the applicable time scales of seasonality can be added.
Smoothing parameters - The seasonality (seasonality.prior.scale) and holiday smoothing (holidays.prior.scale) parameters allow the analyst to tell the model how much of the historical seasonal variation is expected in the future.
[1] Taylor, S. J., & Letham, B. (2017, January 13). Forecasting at Scale. Retrieved from https://facebookincubator.github.io/prophet/static/prophet_paper_20170113.pdf
[2] Tutorial: https://facebookincubator.github.io/prophet/docs/installation.html
Nan (Nandini) Hanagud
slack me @ nan_hanagud on a2mads