【发布时间】:2021-01-09 21:14:08
【问题描述】:
我打算为我模拟其数据的ARIMA 预测方法找到均方根误差。我的方法是使用R 完成的,因为我遵循Rob J. Hyndman 方法:
- 将时间序列数据分为
train和test集。 - 通过
auto.arima()函数获取最佳模型 - 对未来的训练数据集进行预测,直至测试集的长度。
- 计算预测的
RMSE。
MWE
library(forecast)
n=50
phi <- 0.6
set.seed(106100125)
ar1 <- arima.sim(n, model = list(ar=phi, order = c(1, 0, 0)), sd = 1)
train <- head(ar1, round(length(ar1) * 0.8)) # Train set
test <- tail(ar1, length(ar1) - length(train)) # Test set
nfuture <- forecast(train, model = auto.arima(train), h = length(test)) # makes the `forecast of test set to the future up to length of test set
RMSE <- accuracy(test, nfuture) # RETURN RMSE
当我在 MWE 中使用 RMSE 时,我得到了 0。但是当我打电话给test 和nfuture 时,我得到了
#[1] 1.0470537 0.3984545 0.5811056 2.2703350 -1.0060028 -1.6126040 -0.4329466 2.1523534 1.2588265 0.7308986
和
#[1] 0.55281252 0.42374990 0.32481894 0.24898494 0.19085556 0.14629738 0.11214200 0.08596072 0.06589186 0.05050839
分别表明两者不相似,因此RMSE不能是0
请帮助我解决我做错了什么,并让我完成我需要做的事情来纠正它。
【问题讨论】:
标签: r time-series forecast