【发布时间】:2019-12-28 22:35:12
【问题描述】:
我在tsCV(滚动预测来源)中有一个循环超过 4 种时间序列预测方法的循环。列表中的第三个方法 y 不会中断循环。但是,结果表 z 的目的是存储此用户定义函数的 MAE(平均绝对误差)记录 NaN。
这个预测函数是用户定义的,我需要指定damped=T
library(forecast)
x <- 8 # t +
y <- list(ses
, holt
, function(j, k){forecast(holt(j, h=k, damped=T))}, hw
)
z <- list()
for (i in seq_along(y))
{
a <- data.frame(tsCV(AirPassengers, y[[i]], h=x))
a[1:12, ] <- NA # 1st 12 months' forecast likely to be meaningless
b <- colMeans(abs(a), na.rm=T)
c <- data.frame(model = i
,h = 1:x
,mae = b
)
z[[i]] <- c
}
z <- do.call(rbind, z)
z$model <- as.factor(z$model)
我在这里得到了用户定义函数的想法: http://pkg.robjhyndman.com/forecast/reference/tsCV.html#see-also
谢谢。
【问题讨论】:
标签: r loops time-series forecast