使用Prophet交叉验证多个时间序列

使用Prophet交叉验证多个时间序列,r,facebook-prophet,R,Facebook Prophet,我试图交叉验证多个时间序列,并在一个图中绘制所有结果。让我们看一下使用单个时间序列案例的效果 单个TS案例 对于5年期的模拟月度时间序列,我们可以使用以下方法交叉验证预测性能: library(prophet) library(dplyr) library(purrr) ## Dataset creation ds <- seq(as.Date("2014-01-01"), as.Date("2018-12-31"), by = "month") y <- sample(60) d

我试图交叉验证多个时间序列,并在一个图中绘制所有结果。让我们看一下使用单个时间序列案例的效果

单个TS案例

对于5年期的模拟月度时间序列,我们可以使用以下方法交叉验证预测性能:

library(prophet)
library(dplyr)
library(purrr)

## Dataset creation
ds <- seq(as.Date("2014-01-01"), as.Date("2018-12-31"), by = "month")
y <- sample(60)
df <- data.frame(ds, y)
head(df)

m <- prophet(df, seasonality.mode = 'multiplicative')
future <- make_future_dataframe(m, periods = 60)
fcst <- predict(m, future)

df.cv <- cross_validation(m, initial = 730, horizon = 365, period = 180, units = 'days')
plot_cross_validation_metric(df.cv, metric = 'mape')
库(prophet)
图书馆(dplyr)
图书馆(purrr)
##数据集创建
ds
library(prophet)
library(dplyr)
library(purrr)

## Dataset creation
id1 <- rep(12, 60)
ds1 <- seq(as.Date("2014-01-01"), as.Date("2018-12-31"), by = "month")
value1 <- sample(60)

id2 <- rep(132, 48)
ds2 <- seq(as.Date("2015-01-01"), as.Date("2018-12-31"), by = "month")
value2 <- sample(48)

id3 <- rep(210, 72)
ds3 <- seq(as.Date("2013-01-01"), as.Date("2018-12-31"), by = "month")
value3 <- sample(72)

id <- c(id1, id2, id3)
ds <- c(ds1, ds2, ds3)
y <- c(value1, value2, value3)

df <- data.frame(id, ds, y)
head(df)

# preparations
l_df <- df %>% split(.$id)

m_list <- map(l_df, prophet) # prophet call
future_list <- map(m_list, make_future_dataframe, periods = 1) # makes future obs
forecast_list <- map2(m_list, future_list, predict)

df.cv <- cross_validation(m_list, initial = 720, period = 30, horizon = 365, units = 'days')
> df.cv <- cross_validation(m_list, initial = 720, period = 30, horizon = 365, units = 'days')
Error in generate_cutoffs(df, horizon.dt, initial.dt, period.dt) : 
  Less data than horizon after initial window. Make horizon or initial shorter.
In addition: Warning messages:
1: In max(df$ds) : no non-missing arguments to max; returning -Inf
2: In min(df$ds) : no non-missing arguments to min; returning Inf
3: In max(df$ds) : no non-missing arguments to max; returning -Inf
4: In min(df$ds) : no non-missing arguments to min; returning Inf