用指数平滑法求预测的RMSE

用指数平滑法求预测的RMSE,r,time-series,R,Time Series,在使用R对时间序列进行指数平滑时,我使用了一个例子 该代码使用1912年至1960年作为训练数据,并生成未来11年的预测 我想将预测值与1961年至1971年的实际值进行比较,但存在两个问题: 获取实际值的“nht_1”返回了一些错误的数字 尝试获取RMSE时会弹出一个错误: ordery中出错:“orderVector1”中未实现类型“list” 如何对其进行校正,并获得预测值的RMSE?多谢各位 注意:除此之外,请使用forecast软件包中的“准确性”命令。我想通过这种方式获得RMSE d

在使用R对时间序列进行指数平滑时,我使用了一个例子

该代码使用1912年至1960年作为训练数据,并生成未来11年的预测

我想将预测值与1961年至1971年的实际值进行比较,但存在两个问题:

获取实际值的“nht_1”返回了一些错误的数字 尝试获取RMSE时会弹出一个错误:

ordery中出错:“orderVector1”中未实现类型“list”

如何对其进行校正,并获得预测值的RMSE?多谢各位

注意:除此之外,请使用forecast软件包中的“准确性”命令。我想通过这种方式获得RMSE

df <- read.csv("D:\\Documents\\nhtemp.csv")

nht <- ts(df$value, 
          start = c(1912),
          end = c(1960),
          frequency = 1)

nht.hw1 <- HoltWinters(df$value, gamma = F); nht.hw1

library(forecast)

nht.forecast <- forecast(nht.hw1, h = 11)
nht.forecast

# I want to compare the forecast with the actual of year 1961 to 1971:
nht_1 <- ts(df$value, 
     start = c(1961),
     end = c(1971),
     frequency = 1)

nht_1
# returns wrong numbers: 49.9 52.3 49.4 51.1 49.4 47.9 49.8 50.9 49.3 51.9 50.8

# For getting its RMSE

library(caret)
postResample(nht_1, nht.forecast)
# Error in order(y) : unimplemented type 'list' in 'orderVector1'

以下是如何检查预测对象准确性的示例:

library(forecast)
data(woolyrnq) #data I will use, it is already a ts object
可以使用stats::window函数来子集ts

如果要使用插入符号:

编辑 使用相关数据:

df <- read.csv("nhtemp.csv")

这是一个极好的答案和帮助!干得好,继续分享,@missue!
nht.hw1 <- HoltWinters(train, gamma = FALSE)
nht.forecast <- forecast(nht.hw1, h = 12)
accuracy(nht.forecast, x = test)
#output
                     ME     RMSE      MAE       MPE     MAPE     MASE      ACF1 Theil's U
Training set  -69.69645 679.9740 554.6501 -1.877270 10.31036 1.136701 0.1882675        NA
Test set     -504.14620 809.8686 638.8314 -9.699182 11.78262 1.309222 0.1399736 0.9250198
library(caret)
RMSE(pred = nht.forecast$mean, #just the mean and not the data frame with the CIs
     obs = test)
#output
809.8686
df <- read.csv("nhtemp.csv")
nht <- ts(df$value, 
          start = c(1912),
          end = c(1971),
          frequency = 1)
train <- window(nht, end = 1960) #just one number as end since its yearly data
test <- window(nht, start = 1961)
nht.hw1 <- HoltWinters(train, gamma = FALSE)
nht.forecast <- forecast(nht.hw1, h = 10)
accuracy(nht.forecast, x = test)
                      ME      RMSE       MAE        MPE      MAPE      MASE        ACF1 Theil's U
Training set -0.25921398 1.7027155 1.3840629 -0.5616971 2.7249636 1.0462208 -0.05478676        NA
Test set     -0.04523057 0.5478937 0.4651413 -0.0981410 0.9080928 0.3516029  0.08720340 0.7664426