使用先知

时间:2019-03-11 15:47:00

标签: 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)
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')

最后一行给我这样的情节,

enter image description here

具有多个时间序列的复杂案例,

假设我们有4个时间序列(可能更多,例如数千个)。我正在尝试获取显示mape值的类似线图。

我在这里做什么,

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

我尝试了不同的输入组合,但是没有用。因此,我想知道如何交叉验证所有模型并从中绘制单个图。任何想法如何做到这一点?

0 个答案:

没有答案