I've used Prophet previously to forecast individual metrics, but I now need to forecast into 2022, using around 3 years of historic data and including multiple groups. I'd rather not create 1000+ forecasts for each possibility, so hoping I can do this within Prophet.
I've read through a couple of solutions on Stackoverflow which work for a singular group, but I have 3 different groups to forecast.
Below I've created a sample table, with dummy Y data showing how the data is formatted: (Note: There can and will be zero values, but I can exclude them if it'd negatively affect the outputs)
ds | establishment | category | channel | y |
---|---|---|---|---|
2020-01-01 | High School | Stationery | Direct | 27 |
2020-01-01 | High School | Stationery | Paid Search | 31 |
2020-01-01 | High School | Arts | Direct | 47 |
2020-01-01 | High School | Arts | Paid Search | 0 |
2020-01-01 | College | Stationery | Direct | 60 |
2020-01-01 | College | Stationery | Paid Search | 35 |
2020-01-01 | College | Arts | Direct | 54 |
2020-01-01 | College | Arts | Paid Search | 15 |
2020-01-02 | High School | Stationery | Direct | 27 |
2020-01-02 | High School | Stationery | Paid Search | 31 |
2020-01-02 | High School | Arts | Direct | 47 |
2020-01-02 | High School | Arts | Paid Search | 0 |
2020-01-02 | College | Stationery | Direct | 60 |
2020-01-02 | College | Stationery | Paid Search | 35 |
2020-01-02 | College | Arts | Direct | 54 |
2020-01-02 | College | Arts | Paid Search | 15 |
2020-01-03 | High School | Stationery | Direct | 27 |
2020-01-03 | High School | Stationery | Paid Search | 31 |
2020-01-03 | High School | Arts | Direct | 47 |
2020-01-03 | High School | Arts | Paid Search | 0 |
2020-01-03 | College | Stationery | Direct | 60 |
2020-01-03 | College | Stationery | Paid Search | 35 |
2020-01-03 | College | Arts | Direct | 54 |
2020-01-03 | College | Arts | Paid Search | 15 |
... | ... | ... | ... | ... |
The following code works for a single group, but I'd like to expand this to include all groups.
d1 <- df %>%
nest(-establishment) %>%
mutate(m = map(data, prophet)) %>%
mutate(future = map(m, make_future_dataframe, period = 730)) %>%
mutate(forecast = map2(m, future, predict))
d <- d1 %>%
unnest(forecast) %>%
select(ds, establishmentShortcut, yhat)
If anybody can recommend a solution, I'd appreciate it.