R:forecast() 函数产生的预测比规定的预测范围 'h' 多。为什么?

R: forecast() function producing more forecasts than the stated forecasts horizon 'h'. Why?

我正在使用动态回归模型来预测一分钟一分钟的时间序列。但是,预测期与指定的 'h' 值不匹配。但它们更符合训练数据集的长度。训练数据集为 2 周,而测试数据集为 1 周,以分钟为单位。我在 forecast() 函数中指定 h = 60*24*7 =10080 分钟(1 周),但是,预测长度为 20160,即两周。

我检查了是否与训练集的长度有任何相关性。显然,有。如果我输入三周的训练数据集,它将产生三周的预测。

xreg <- fourier(msts_train_10, K= c(15,5))
fit4 <- auto.arima(msts_train_10, xreg=xreg, seasonal=FALSE, stationary=TRUE)
fc4 <- forecast(fit4, xreg =  xreg, h = 10080)
accuracy(fc4,msts_total)
autoplot(fc4)


> length(fc4$mean)
[1] 20160

我预计只生成 1 周的预测(10080 个值)。如何修复此错误?

请花时间阅读帮助文件。在这种情况下,他们提供了一个简单的解决方案。

h : Number of periods for forecasting. If xreg is used, h is ignored and the number of forecast periods is set to the number of rows of xreg.

由于您使用 fourier() 生成 xreg,并且您没有在该函数中使用 h 参数,因此 xreg 的行数与训练数据。 (再次尝试阅读帮助文件。)