Follow-up Forecasting Forum - Rob J. HyndmanDi˙erent types of residuals fit
Transcript of Follow-up Forecasting Forum - Rob J. HyndmanDi˙erent types of residuals fit
1
Follow-upForecastingForumRob J Hyndman
18 April 2017
Outline
1 fpp2
2 forecast v8
3 forecastHybrid
4 opera
5 prophet
6 Forecasting Q&A
7 Wishlist for forecast v9.0
2
fpp2
OTexts.org/fpp2/
fpp2 package for data and functions on CRANAutomatically loads forecast and ggplot2
3
Outline
1 fpp2
2 forecast v8
3 forecastHybrid
4 opera
5 prophet
6 Forecasting Q&A
7 Wishlist for forecast v9.0
4
head and tail
head(lynx)
## Time Series:## Start = 1821## End = 1826## Frequency = 1## [1] 269 321 585 871 1475 2821
5
head and tail
tail(uschange)
## Consumption Income Production Savings Unemployment
## 2015 Q2 0.708 0.955 -0.697 5.024 -0.1
## 2015 Q3 0.665 0.802 0.381 3.181 -0.3
## 2015 Q4 0.562 0.740 -0.846 3.483 0.0
## 2016 Q1 0.405 0.519 -0.418 2.237 0.0
## 2016 Q2 1.048 0.724 -0.203 -2.722 -0.1
## 2016 Q3 0.730 0.645 0.475 -0.573 0.0
6
gghistogram()
gghistogram(lynx)
0
20
40
60
0 2000 4000 6000 8000
lynx
coun
t
7
gghistogram()
gghistogram(lynx, add.normal=TRUE)
0
20
40
60
−4000 0 4000 8000
lynx
coun
t
8
gghistogram()
gghistogram(lynx, add.kde=TRUE)
0
20
40
60
0 2000 4000 6000 8000
lynx
coun
t
9
checkresiduals()
fit <- auto.arima(WWWusage)checkresiduals(fit)
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
● ●●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
● ●
●
●●
●
●●
●
●●
●
●
●
● ●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
● ●
−5
0
5
0 20 40 60 80 100
Residuals from ARIMA(1,1,1)
−0.2
−0.1
0.0
0.1
0.2
5 10 15 20
Lag
AC
F
0
5
10
15
20
−10 −5 0 5 10
residuals
coun
t
10
checkresiduals()
#### Ljung-Box test#### data: Residuals from ARIMA(1,1,1)## Q* = 8, df = 8, p-value = 0.4#### Model df: 2. Total lags used: 10
11
Different types of residuals
fit <- ets(woolyrnq)res <- cbind(Residuals = residuals(fit),
RespRes = residuals(fit, type='response'))autoplot(res, facets=TRUE)
Residuals
RespR
es
1970 1980 1990
−0.2
−0.1
0.0
0.1
−1000
−500
0
500
1000
Time
res
12
Different types of residuals
fit <- Arima(lynx, order=c(4,0,0), lambda=0.5)res <- cbind(Residuals = residuals(fit),
RespRes = residuals(fit, type='response'))autoplot(res, facets=TRUE)
Residuals
RespR
es
1820 1840 1860 1880 1900 1920
−50
−25
0
25
−2000
−1000
0
1000
2000
3000
Time
res
13
Different types of residuals
fit <- auto.arima(uschange[,"Consumption"],xreg=uschange[,"Income"])
res <- cbind(Residuals = residuals(fit),RegRes = residuals(fit, type='regression'))
autoplot(res, facets=TRUE)
Residuals
RegR
es
1960 1980 2000
−2
−1
0
1
−2
−1
0
1
Time
res
14
ggseasonplot()
ggseasonplot(USAccDeaths)
7000
8000
9000
10000
11000
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
Month
year1973
1974
1975
1976
1977
1978
Seasonal plot: USAccDeaths
15
ggseasonplot(polar=TRUE)
ggseasonplot(USAccDeaths, polar=TRUE)
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
Jan/
7000
8000
9000
10000
11000
Month
year1973
1974
1975
1976
1977
1978
Seasonal plot: USAccDeaths
16
autolayer()
WWWusage %>% ets %>% forecast(h=20) -> fcautoplot(WWWusage, series="Data") +
autolayer(fc, series="Forecast") +autolayer(fitted(fc), series="Fitted")
100
150
200
250
300
350
0 20 40 60 80 100 120
Time
WW
Wus
age series
Data
Fitted
Forecast
17
Time series cross-validation
Traditional evaluation
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● timeTraining data Test data
18
Time series cross-validation
Traditional evaluation
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● timeTraining data Test data
Time series cross-validation (h = 1)● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●
time
Forecast accuracy averaged over test sets.Also known as “evaluation on a rollingforecasting origin” 19
Time series cross-validation
Traditional evaluation
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● timeTraining data Test data
Time series cross-validation (h = 2)● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●
time
Forecast accuracy averaged over test sets.Also known as “evaluation on a rollingforecasting origin” 20
Time series cross-validation
Traditional evaluation
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● timeTraining data Test data
Time series cross-validation (h = 3)● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●
time
Forecast accuracy averaged over test sets.Also known as “evaluation on a rollingforecasting origin” 21
Time series cross-validation
Traditional evaluation
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● timeTraining data Test data
Time series cross-validation (h = 4)● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●
time
Forecast accuracy averaged over test sets.Also known as “evaluation on a rollingforecasting origin” 22
Time series cross-validation
Traditional evaluation
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● timeTraining data Test data
Time series cross-validation (h = 5)● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●
time
Forecast accuracy averaged over test sets.Also known as “evaluation on a rollingforecasting origin” 23
tsCV()
e <- tsCV(dj, rwf, drift=TRUE, h=1)sqrt(mean(e^2, na.rm=TRUE))
## [1] 22.7
sqrt(mean(residuals(rwf(dj, drift=TRUE))^2,na.rm=TRUE))
## [1] 22.5
A good way to choose the best forecasting model is to find themodel with the smallest RMSE computed using time seriescross-validation. 24
Pipe function
Ugly code:e <- tsCV(dj, rwf, drift=TRUE, h=1)sqrt(mean(e^2, na.rm=TRUE))sqrt(mean(residuals(rwf(dj, drift=TRUE))^2, na.rm=TRUE))
Better with a pipe:dj %>% tsCV(forecastfunction=rwf, drift=TRUE, h=1) -> ee^2 %>% mean(na.rm=TRUE) %>% sqrtdj %>% rwf(drift=TRUE) %>% residuals -> resres^2 %>% mean(na.rm=TRUE) %>% sqrt
25
Autoregressive crossvalidation
5-fold cross-validation
5-fold non-dep. cross-validation
OOS evaluation
retraining and evaluation with new, unknown data
26
Autoregressive crossvalidation
cross-validation
OOSevaluation
non-dep.cross-
validation
yt yt+1yt-1yt-2yt-3 yt yt+1yt-1yt-2yt-3 yt yt+1yt-1yt-2yt-3
27
Autoregressive crossvalidation
modelcv <- CVar(lynx, k=5, lambda=0.15)print(modelcv)
## Series: lynx## Call: CVar(y = lynx, k = 5, lambda = 0.15)#### 5-fold cross-validation## Mean SD## ME 57.384 437.579## RMSE 975.938 238.318## MAE 636.672 152.297## MPE -17.982 19.380## MAPE 56.278 15.635## ACF1 0.144 0.264## Theil's U 0.912 0.541
CVar only handles nnetar models.If there is enough interest, I might add more functionalityat a later stage.
28
Bagged ETS
Algorithm: Generating bootstrapped seriesbootstrap ← function(ts, num.boot) {
lambda ← BoxCox.lambda(ts, min=0, max=1)ts.bc ← BoxCox(ts, lambda)if(ts is seasonal) {
[trend, seasonal, remainder] ← stl(ts.bc)}else {
seasonal ← 0[trend, remainder] ← loess(ts.bc)
}recon.series[1] ← tsfor(i in 2:num.boot) {
boot.sample[i] ← MBB(remainder)recon.series.bc[i] ← trend + seasonal + boot.sample[i]recon.series[i] ← InvBoxCox(recon.series.bc[i], lambda)
}return(recon.series) 29
Bagged ETSM
495B
ox−C
ox transformed
1982 1985 1988 1990 1992
3000
4000
5000
4.00
4.05
4.10
4.15
Time
df
30
Bagged ETS
data
tren
dse
ason
alre
mai
nder
1982 1984 1986 1988 1990 1992
4.00
4.05
4.10
4.15
3.99
4.02
4.05
4.08
4.11
−0.02
0.00
0.02
−0.01
0.00
0.01
Time
31
Bagged ETS
data
tren
dse
ason
alre
mai
nder
1982 1984 1986 1988 1990 1992
3.95
4.00
4.05
4.10
3.99
4.02
4.05
4.08
4.11
−0.02
0.00
0.02
−0.005
0.000
0.005
Time
32
Bagged ETS
3000
4000
5000
6000
1982 1984 1986 1988 1990 1992
Year
M49
5
33
Bagged ETS
3000
4000
5000
6000
1982 1984 1986 1988 1990 1992
Year
M49
5
34
Bagged ETS
3000
4000
5000
6000
1982 1984 1986 1988 1990 1992
Year
M49
5
35
Bagged ETS
baggedETS(Mcomp::M3[[1896]]$x) %>%forecast %>% autoplot +xlab("Year") + ylab("M495")
3000
4000
5000
6000
1982 1984 1986 1988 1990 1992
Year
M49
5
Forecasts from baggedETS
36
Bagged ETS
3000
4000
5000
6000
1982 1984 1986 1988 1990 1992
Year
M49
5
Forecasts from baggedETS
Intervals show range of point forecastsThey are not prediction intervals
37
Outline
1 fpp2
2 forecast v8
3 forecastHybrid
4 opera
5 prophet
6 Forecasting Q&A
7 Wishlist for forecast v9.0
38
Different CO2 forecasts
train <- window(co2, end=c(1990,12))test <- window(co2, start=c(1991,1))h <- length(test)ETS <- forecast(ets(train), h=h)ARIMA <- forecast(auto.arima(train, lambda=0), h=h)STL <- stlf(train, lambda=0, h=h)
39
Different CO2 forecasts
autoplot(co2) + xlab("Year") +ylab(expression("Atmospheric concentration of CO"[2])) +autolayer(ETS, PI=FALSE, series="ETS") +autolayer(ARIMA, PI=FALSE, series="ARIMA") +autolayer(STL, PI=FALSE, series="STL")
320
330
340
350
360
370
1960 1970 1980 1990
Year
Atm
osph
eric
con
cent
ratio
n of
CO
2
seriesARIMA
ETS
STL
40
forecastHybrid
Fits ARIMA, ETS, Theta, NNETAR, STL-ETS andTBATS models(Weighted) average of the point forecastsNo proper prediction intervals.
41
forecastHybrid
library(forecastHybrid)fit1 <- hybridModel(train, weights="equal")
## Fitting the auto.arima model## Fitting the ets model## Fitting the thetam model## Fitting the nnetar model## Fitting the stlm model## Fitting the tbats model
fit2 <- hybridModel(train, weights="insample")
## Fitting the auto.arima model## Fitting the ets model## Fitting the thetam model## Fitting the nnetar model## Fitting the stlm model## Fitting the tbats model
fc1 <- forecast(fit1, h=h)fc2 <- forecast(fit2, h=h)
42
forecastHybrid
autoplot(fc1) + ggtitle("Hybrid 1") + xlab("Year") +ylab(expression("Atmospheric concentration of CO"[2]))
320
330
340
350
360
370
1960 1970 1980 1990
Year
Atm
osph
eric
con
cent
ratio
n of
CO
2
level80
95
Hybrid 1
43
forecastHybrid
autoplot(co2) + xlab("Year") +ylab(expression("Atmospheric concentration of CO"[2])) +autolayer(fc1, series="Hybrid1", PI=FALSE) +autolayer(fc2, series="Hybrid2", PI=FALSE)
320
330
340
350
360
1960 1970 1980 1990
Year
Atm
osph
eric
con
cent
ratio
n of
CO
2
seriesHybrid1
Hybrid2
44
forecastHybrid
mse <- c(Hybrid1=mean((test - fc1$mean)^2),Hybrid2=mean((test - fc2$mean)^2),ETS= mean((test - ETS$mean)^2),ARIMA= mean((test - ARIMA$mean)^2),STL= mean((test - STL$mean)^2))
round(mse,2)
## Hybrid1 Hybrid2 ETS ARIMA STL## 0.93 0.73 5.92 2.35 2.04
45
Outline
1 fpp2
2 forecast v8
3 forecastHybrid
4 opera
5 prophet
6 Forecasting Q&A
7 Wishlist for forecast v9.0
46
opera
Online Prediction by E xpeRt Aggregation
mixture function computes weights whencombining forecasts based on how well it hasdone up to that point.
47
opera
library(opera)X <- cbind(ETS=ETS$mean, ARIMA=ARIMA$mean, STL=STL$mean)MLpol0 <- mixture(model = "MLpol", loss.type = "square")weights <- predict(MLpol0, X, test, type='weights')head(weights)
## X1 X2 X3## [1,] 0.333 0.333 0.333## [2,] 0.560 0.000 0.440## [3,] 0.617 0.000 0.383## [4,] 1.000 0.000 0.000## [5,] 1.000 0.000 0.000## [6,] 1.000 0.000 0.000
48
opera
library(opera)X <- cbind(ETS=ETS$mean, ARIMA=ARIMA$mean, STL=STL$mean)MLpol0 <- mixture(model = "MLpol", loss.type = "square")weights <- predict(MLpol0, X, test, type='weights')tail(weights)
## X1 X2 X3## [79,] 0.360 0.294 0.346## [80,] 0.280 0.334 0.386## [81,] 0.277 0.336 0.387## [82,] 0.358 0.298 0.344## [83,] 0.214 0.369 0.417## [84,] 0.233 0.359 0.408
49
opera
z <- ts(predict(MLpol0, X, test, type='response'),start=c(1991,1), freq=12)
autoplot(co2, series="Data") + xlab("Year") +ylab(expression("Atmospheric concentration of CO"[2])) +autolayer(z, series="Mixture")
320
330
340
350
360
1960 1970 1980 1990
Year
Atm
osph
eric
con
cent
ratio
n of
CO
2
seriesData
Mixture
50
opera
mse <- c(Opera=mean((test-z)^2),Hybrid1=mean((test - fc1$mean)^2),Hybrid2=mean((test - fc2$mean)^2))
round(mse,2)
## Opera Hybrid1 Hybrid2## 0.25 0.93 0.73
Opera weights are updated using past test data, socomparison not “fair”.
51
Outline
1 fpp2
2 forecast v8
3 forecastHybrid
4 opera
5 prophet
6 Forecasting Q&A
7 Wishlist for forecast v9.0
52
prophet model
yt = gt + st + ht + εt
yt = daily time series.gt = “growth function” (trend-cycle).st = Fourier seasonal terms: weekly and/or yearlyht = holiday effect.εt = error (can be ARMA errors).Estimated as a Bayesian regression using Stan
53
Growth function
Piecewise linear growth function
gt = (k + atδ)t + (b + aTt γ)
Changepoints at times sj, j = 1, . . . , S.
aj,t =
1 if t ≥ sj0 otherwise
.
Changepoints can be specified (e.g., productlaunches) or automatically selected.A piecewise logistic growth is also available
54
Holidays and Events
Dummy holiday/event effects
ht =L∑i=1κi1(t ∈ Di)
L = number of different types of holidays.Di = dates for holiday type i.
55
prophet example
56
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●●
●
●
●●●
●
●
●
●
●
●●●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●●
●
●
●
●
●●●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
2013 2014 2015 2016 2017Date
Num
ber
of E
vent
s on
Fac
eboo
k
prophet example
57
holidaystrend
weekly
yearly
2013 2014 2015 2016 2017Date
Com
pone
nt V
alue
prophet example
library(prophet)history <- data.frame(
y = hyndsight,ds = seq(as.Date('2014-04-30'),
as.Date('2015-04-29'), by = 'd'))m <- prophet(history)future <- make_future_dataframe(m, periods = 365)forecast <- predict(m, future)
58
prophet example
plot(m, forecast)
●●
●
●●
●
●
●
●●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●●
●
●
●
●●●
●
●
●
●
●
●
●
●
●●
●●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●●
●
●
●●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●●
●
●
●
●
●
●●
●
●
●●
●
●
●
●
●
●●
●
●●
●
●
●
●●
●
●
●
●
●
●●
●
●
●
●
●
●●
●
●
●
●
●●
●
●
●
●
●
●
●●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●●●
●
●
●
●●
●●
●
●
●
●
●●●●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●●
●
●
●
●●
●
●
●
●●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●●
●
●
●
●
●●●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●●
●
●
●
●
●
●●
●
●
●
●●
●
●
●
●
●
●
●
0
1000
2000
3000
2014−07 2015−01 2015−07 2016−01
ds
y
59
prophet pros and cons
Pros
Completely automatic including changepointsHandles multiple seasonality and holiday effects
Cons
Only for daily dataSeems to overfit annual seasonalityNumber of Fourier terms is hard-coded
Compare
Similar to dynamic harmonic regression with ARMAerrors, but with changepoint selection automated.
60
Outline
1 fpp2
2 forecast v8
3 forecastHybrid
4 opera
5 prophet
6 Forecasting Q&A
7 Wishlist for forecast v9.0
61
Forecasting Q&A
What forecasting have you been doing?
Have you been using the forecast
package?
Have you run into any forecasting
problems?
Have you run into any R problems?
62
Outline
1 fpp2
2 forecast v8
3 forecastHybrid
4 opera
5 prophet
6 Forecasting Q&A
7 Wishlist for forecast v9.0
63
Wishlist for forecast v9.0
What facilities would you like to see in the
next version of the forecast package?
What topics would you like to see covered
in the fpp book?
64
My plans for forecast v9+
forecast v9+New multiple-seasonality method which allowstime-changing seasonality and covariates (crossbetween prophet and tbats).Methods for forecasting count time series.Improved method for selecting seasonaldifferencing in auto.arima().Somethink like forecastHybrid but withproper prediction intervals.Better forecast.ts() for a wider range of timeseries.PSO for ETS. 65
sugrrants
sugrrants packageSUpporting GRaphs with R for ANalysing TimeSeriesNew package for time series data andvisualizationWorks with tidyverse packages.Some parts of forecast to move?Calendar plotshttps://github.com/earowang/sugrrants
66