【发布时间】:2019-12-16 23:43:48
【问题描述】:
我想我在这里遗漏了一些非常明显的东西。当我在 forecast 包中计算测试集的 RMSE 时,我得到一个非常小的数字:8.581624。但是当我将 ts 对象强制转换为 numeric 向量时,我的 RMSE 会爆炸到:51.9861。
我错过了什么?
library(forecast)
library(fpp2)
train <- window(ausbeer, end=c(2005,3))
fit <- auto.arima(train, lambda=0)
summary(fit)
accuracy(forecast(fit, h=20), x=tail(ausbeer,20))
# Test set RMSE 8.581624
但是当我将预测和实际值存储为数字向量时,RMSE 会变得很奇怪。
test_actuals <- as.numeric(tail(ausbeer,20))
test_preds <- as.numeric(forecast(fit, h=20)$mean)
Metrics::rmse(test_actuals, test_preds)
# RMSE 51.9861
从视觉上看,数字转换工作正常。
> test_actuals
[1] 408 482 438 386 405 491 427 383 394 473 420 390 410 488 415 398 419 488 414 374
> tail(ausbeer,20)
Qtr1 Qtr2 Qtr3 Qtr4
2005 408 482
2006 438 386 405 491
2007 427 383 394 473
2008 420 390 410 488
2009 415 398 419 488
2010 414 374
>
> test_preds
[1] 478.7813 425.9601 389.2990 406.7974 480.3568 422.6604 388.2854 405.5242 478.4310 421.2396 386.9089 404.0702
[13] 476.7475 419.7445 385.5367 402.6393 475.0574 418.2569 384.1705 401.2124
>
> forecast(fit, h=20)$mean
Qtr1 Qtr2 Qtr3 Qtr4
2005 478.7813
2006 425.9601 389.2990 406.7974 480.3568
2007 422.6604 388.2854 405.5242 478.4310
2008 421.2396 386.9089 404.0702 476.7475
2009 419.7445 385.5367 402.6393 475.0574
2010 418.2569 384.1705 401.2124
【问题讨论】:
标签: r time-series forecast