指定预测期不限制预测输出
Specified forecast period not constraining forecast output
我正在尝试构建一个 10 年长时间序列的 ARIMA 模型,并用它来预测未来一年。为了测试我的模型,我训练了 9 年的数据,预测了 1 年的数据,并将预测值与当年的实际值进行了比较。
问题:我告诉 forecast() 将其预测的周期限制为 365,即 1 年。但是当我绘制输出时,它似乎输出 9 年或大约 3285 的 "h="。为什么会这样?
##The time series is 3650 daily observations of rainfall
x <- ts(x$obs, start=c(2007, 10), end=c(2017, 9), frequency = 365)
##create training set - first 9 years of observations
x_train <- subset(x, start = 1, end = 3285)
##test set - last year of observations
x_test <- subset(x, start = 3286, end = 3650)
##fit the model
x_train_fit <- auto.arima(x_train, seasonal=FALSE, xreg=fourier(x_train, K=1))
##forecast using the model
x_fcast_test <- forecast(x_train_fit,h=365, xreg=fourier(x_train, K=1))
plot(x_fcast_test, col="black")
lines(x_test,col="red")
更新: Rob Hyndman 在下面的回答是正确的。预测期的数量将设置为 xreg 的行数,因为当使用 xreg 时,它有利于 h=,所以我的 h= 没有被使用。因此,将整个训练集作为 exreg 传递会创建与训练集长度相等的预测。
x_fcast_test <- forecast(x_train_fit,h=365, xreg=fourier(x_test, K=1))
plot(x_fcast_test, col="black")
lines(x_test,col="red")
阅读提供的帮助文件总是值得的。在这种情况下:
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
.
您在 xreg
参数中传递了训练数据,因此您得到的预测与观察到的一样多。
据推测,您打算使用 xreg
参数的测试数据。
我正在尝试构建一个 10 年长时间序列的 ARIMA 模型,并用它来预测未来一年。为了测试我的模型,我训练了 9 年的数据,预测了 1 年的数据,并将预测值与当年的实际值进行了比较。
问题:我告诉 forecast() 将其预测的周期限制为 365,即 1 年。但是当我绘制输出时,它似乎输出 9 年或大约 3285 的 "h="。为什么会这样?
##The time series is 3650 daily observations of rainfall
x <- ts(x$obs, start=c(2007, 10), end=c(2017, 9), frequency = 365)
##create training set - first 9 years of observations
x_train <- subset(x, start = 1, end = 3285)
##test set - last year of observations
x_test <- subset(x, start = 3286, end = 3650)
##fit the model
x_train_fit <- auto.arima(x_train, seasonal=FALSE, xreg=fourier(x_train, K=1))
##forecast using the model
x_fcast_test <- forecast(x_train_fit,h=365, xreg=fourier(x_train, K=1))
plot(x_fcast_test, col="black")
lines(x_test,col="red")
更新: Rob Hyndman 在下面的回答是正确的。预测期的数量将设置为 xreg 的行数,因为当使用 xreg 时,它有利于 h=,所以我的 h= 没有被使用。因此,将整个训练集作为 exreg 传递会创建与训练集长度相等的预测。
x_fcast_test <- forecast(x_train_fit,h=365, xreg=fourier(x_test, K=1))
plot(x_fcast_test, col="black")
lines(x_test,col="red")
阅读提供的帮助文件总是值得的。在这种情况下:
h
: Number of periods for forecasting. Ifxreg
is used,h
is ignored and the number of forecast periods is set to the number of rows ofxreg
.
您在 xreg
参数中传递了训练数据,因此您得到的预测与观察到的一样多。
据推测,您打算使用 xreg
参数的测试数据。