您可以使用 freq = "month" 选项与 dplyr 一起制作未来的数据帧。下面将预测接下来的 2 个月。
Region <- c('Region_1','Region_1','Region_1','Region_1','Region_2','Region_2','Region_2','Region_2')
Value <- c(123123, 223333, 11133, 882822,300000,22333,23232323,23232323)
Month <- as.Date(c('2017-01-01','2017-02-01','2017-03-01','2017-04-01',
'2017-01-01','2017-02-01','2017-03-01','2017-04-01'))
df <- data.frame(Month, Region, Value)
names(df)[1] <- 'ds'
names(df)[3] <- 'y'
install.packages("prophet")
library(prophet)
library(dplyr)
new_df = df %>%
group_by(Region) %>%
do(predict(prophet(., yearly.seasonality = TRUE),
make_future_dataframe(prophet(., yearly.seasonality = TRUE), freq = "month", periods = 2))) %>%
select(ds, Region, yhat)
new_df
输出:
# A tibble: 12 x 3
# Groups: Region [2]
ds Region yhat
<dttm> <chr> <dbl>
1 2017-01-01 00:00:00 Region_1 123123.
2 2017-02-01 00:00:00 Region_1 223333
3 2017-03-01 00:00:00 Region_1 11133.
4 2017-04-01 00:00:00 Region_1 882822.
5 2017-05-01 00:00:00 Region_1 -110249.
6 2017-06-01 00:00:00 Region_1 11870506.
7 2017-01-01 00:00:00 Region_2 300000.
8 2017-02-01 00:00:00 Region_2 22333.
9 2017-03-01 00:00:00 Region_2 23232323.
10 2017-04-01 00:00:00 Region_2 23232323.
11 2017-05-01 00:00:00 Region_2 -486859040.
12 2017-06-01 00:00:00 Region_2 218123552.