mitchelloharawild / fable.prophet

fable extension for the prophet forecasting procedure
https://pkg.mitchelloharawild.com/fable.prophet
55 stars 8 forks source link

Period selection for quarterly data #28

Open robjhyndman opened 3 years ago

robjhyndman commented 3 years ago

I was expecting each of these to be the same.

In particular, the second one seems to choose a period of 16 quarters, while the first seems to have an even longer period.

library(fable.prophet)
library(dplyr)

fit <- tsibble::as_tsibble(tsibbledata::aus_production) %>%
  model(
    auto = prophet(Cement),
    yearly = prophet(Cement ~ season("year")),
    period4 = prophet(Cement ~ season(period=4, order=2))
  )
fit %>% select(auto) %>% components() %>% autoplot()

fit %>% select(yearly) %>% components() %>% autoplot()

fit %>% select(period4) %>% components() %>% autoplot()

Created on 2020-12-08 by the reprex package (v0.3.0)

mitchelloharawild commented 3 years ago

This is working as intended, and the surprising behaviour is due to the defaults of prophet::prophet():

auto = prophet(Cement)

The default seasonalities included in a prophet model are always daily, weekly, and annual. As I understand, the model is designed for forecasting daily aggregate data on Facebook events and does not have appropriate defaults for >daily data..

Some docs on forecasting monthly data with Prophet is here: https://facebook.github.io/prophet/docs/non-daily_data.html#monthly-data

From this example, the months are represented as YYYY-MM-01, and they're used the same default model with default seasonalities (including daily and weekly) for modelling monthly data. The same (poor) defaults are used here for compatibility.

yearly = prophet(Cement ~ season("year"))

The default order of annual seasonal fourier terms is always 10, regardless of the data's interval. As >monthly data is represented as daily via YYYY-MM-01, this default is possible but terrible. {fable.prophet} does not interfere with these defaults and acts as a wrapper to the {prophet} package only, so that (for the most part) {prophet} model parameters can be directly translated and used with {fable.prophet}.

period4 = prophet(Cement ~ season(period=4, order=2))

This estimates a model that is appropriate for the data.