使用 Mcomp 包对每月时间序列进行批量预测时如何获得正确的输出?
Posted
技术标签:
【中文标题】使用 Mcomp 包对每月时间序列进行批量预测时如何获得正确的输出?【英文标题】:How to get the correct output when using batch forecasting for the monthly time series with the Mcomp package? 【发布时间】:2022-01-20 18:24:27 【问题描述】:我正在尝试使用 Mcomp
包对每月时间序列进行批量预测。我已经准备了一个代码,但我没有得到任何输出。
library(forecast)
library(Mcomp)
使用 seq
函数,因为我需要选择以 7 结尾的特定时间序列。
tsset <- (seq(1507, 2797, 10))
tsset
horizon <- 18
fit1<-array(0,130)
for (tsi in 1:130)
y <- tsset[[tsi]]$x
yt <- head(y, length(y) - horizon)
yv <- tail(y, horizon)
for(i in 1:130)
fit1 <-c(ets(yt))
print(fit1)
【问题讨论】:
【参考方案1】:在给定时间序列的前 112 个点的情况下,您可以通过以下方式获得最后 18 个点的预测(您不需要循环):
tsset<- seq(1507, 2797, 10) + 10*runif(130) # add noise
horizon <- 18
y <- tsset
n <- length(y)
yt <- head(y, n - horizon)
#yv <- tail(y, horizon)
fit1 <- ets(yt)
yv1 <- forecast(fit1, h=horizon)
start <- n - horizon + 1
plot(start:n, yv, type='l', col='red', lty=1, xlab='t', ylab='y(t)')
lines(start:n, yv1$mean, col='blue', lty=2)
lines(start:n, yv1$upper[,2], col='green', lty=2)
lines(start:n, yv1$lower[,2], col='green', lty=2)
legend("topleft", legend=c("original", "forecast", "95% CI"),
col=c("red", "blue", "green"), lty=c(1,2,2), cex=0.8)
【讨论】:
以上是关于使用 Mcomp 包对每月时间序列进行批量预测时如何获得正确的输出?的主要内容,如果未能解决你的问题,请参考以下文章
R语言使用caret包对GBM模型参数调优(自定义调优的评估指标,例如ROC指标):抽取预测标签及类概率抽样ROC的指标并绘制密度图