使用 fable 包的预测中只有 NaNs 准确 table
Only NaNs in accuracy table in forecasts using fable package
我有这个数据,
> dput(dt_tsbl)
structure(list(series.id = c(225L, 225L, 225L, 225L, 225L, 225L,
225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L,
225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L,
225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L,
225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L,
225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L, 365L,
365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L,
365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L,
365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L,
365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L,
365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L,
365L, 365L, 365L, 365L, 585L, 585L, 585L, 585L, 585L, 585L, 585L,
585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L,
585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L,
585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L,
585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L,
585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L), series.total = c(281L,
337L, 397L, 413L, 304L, 295L, 331L, 280L, 471L, 397L, 335L, 165L,
323L, 383L, 400L, 394L, 402L, 562L, 408L, 356L, 509L, 548L, 460L,
367L, 425L, 412L, 416L, 493L, 469L, 372L, 379L, 393L, 482L, 420L,
406L, 298L, 371L, 394L, 436L, 339L, 513L, 401L, 328L, 376L, 525L,
522L, 409L, 333L, 451L, 381L, 477L, 464L, 378L, 422L, 374L, 404L,
438L, 503L, 425L, 299L, 18L, 17L, 15L, 17L, 14L, 23L, 24L, 20L,
45L, 24L, 17L, 13L, 14L, 16L, 24L, 30L, 57L, 29L, 26L, 27L, 30L,
35L, 25L, 20L, 22L, 26L, 28L, 42L, 31L, 31L, 24L, 22L, 64L, 21L,
25L, 22L, 24L, 18L, 15L, 19L, 46L, 23L, 22L, 25L, 21L, 18L, 26L,
14L, 9L, 15L, 18L, 13L, 12L, 17L, 30L, 16L, 22L, 22L, 23L, 20L,
182L, 211L, 298L, 172L, 263L, 248L, 263L, 223L, 282L, 224L, 246L,
189L, 182L, 232L, 272L, 236L, 215L, 301L, 290L, 251L, 263L, 286L,
282L, 266L, 258L, 224L, 239L, 245L, 274L, 261L, 301L, 247L, 234L,
265L, 272L, 230L, 234L, 259L, 242L, 224L, 264L, 229L, 248L, 213L,
288L, 279L, 244L, 239L, 201L, 195L, 212L, 222L, 286L, 246L, 222L,
254L, 339L, 270L, 243L, 267L), mth = structure(c(16071, 16102,
16130, 16161, 16191, 16222, 16252, 16283, 16314, 16344, 16375,
16405, 16436, 16467, 16495, 16526, 16556, 16587, 16617, 16648,
16679, 16709, 16740, 16770, 16801, 16832, 16861, 16892, 16922,
16953, 16983, 17014, 17045, 17075, 17106, 17136, 17167, 17198,
17226, 17257, 17287, 17318, 17348, 17379, 17410, 17440, 17471,
17501, 17532, 17563, 17591, 17622, 17652, 17683, 17713, 17744,
17775, 17805, 17836, 17866, 16071, 16102, 16130, 16161, 16191,
16222, 16252, 16283, 16314, 16344, 16375, 16405, 16436, 16467,
16495, 16526, 16556, 16587, 16617, 16648, 16679, 16709, 16740,
16770, 16801, 16832, 16861, 16892, 16922, 16953, 16983, 17014,
17045, 17075, 17106, 17136, 17167, 17198, 17226, 17257, 17287,
17318, 17348, 17379, 17410, 17440, 17471, 17501, 17532, 17563,
17591, 17622, 17652, 17683, 17713, 17744, 17775, 17805, 17836,
17866, 16071, 16102, 16130, 16161, 16191, 16222, 16252, 16283,
16314, 16344, 16375, 16405, 16436, 16467, 16495, 16526, 16556,
16587, 16617, 16648, 16679, 16709, 16740, 16770, 16801, 16832,
16861, 16892, 16922, 16953, 16983, 17014, 17045, 17075, 17106,
17136, 17167, 17198, 17226, 17257, 17287, 17318, 17348, 17379,
17410, 17440, 17471, 17501, 17532, 17563, 17591, 17622, 17652,
17683, 17713, 17744, 17775, 17805, 17836, 17866), class = c("yearmonth",
"Date"))), row.names = c(NA, -180L), key = structure(list(series.id = c(225L,
365L, 585L), .rows = list(1:60, 61:120, 121:180)), row.names = c(NA,
-3L), class = c("tbl_df", "tbl", "data.frame"), .drop = TRUE), index = structure("mth", ordered = TRUE), index2 = "mth", interval = structure(list(
year = 0, quarter = 0, month = 1, week = 0, day = 0, hour = 0,
minute = 0, second = 0, millisecond = 0, microsecond = 0,
nanosecond = 0, unit = 0), class = "interval"), class = c("tbl_ts",
"tbl_df", "tbl", "data.frame"))
我正在尝试 运行 一些使用寓言包的预测模型,使用以下行,
library(tidyverse)
library(tsibble)
library(fable)
library(fabletools)
fit1 <- dt_tsbl %>%
model(
arima = ARIMA(series.total),
ets = ETS(series.total),
snaive = SNAIVE(series.total),
)
fit1
预测mable
如下,
> fit1
# A mable: 3 x 4
# Key: series.id [3]
series.id arima ets snaive
<int> <model> <model> <model>
1 225 <ARIMA(0,1,2)(1,0,0)[12]> <ETS(A,N,A)> <SNAIVE>
2 365 <ARIMA(1,0,0) w/ mean> <ETS(M,N,M)> <SNAIVE>
3 585 <ARIMA(0,0,0)(0,0,1)[12] w/ mean> <ETS(A,N,N)> <SNAIVE>
我得到了预测值,
> fc
# A fable: 9 x 5 [1M]
# Key: series.id, .model [9]
series.id .model mth series.total .distribution
<int> <chr> <mth> <dbl> <dist>
1 225 arima 2019 Jan 398. N(398, 4748)
2 365 arima 2019 Jan 22.8 N(23, 98)
3 585 arima 2019 Jan 232. N(232, 979)
4 225 ets 2019 Jan 385. N(385, 3101)
5 365 ets 2019 Jan 14.5 N(14, 21)
6 585 ets 2019 Jan 247. N(247, 1103)
7 225 snaive 2019 Jan 451 N(451, 7661)
8 365 snaive 2019 Jan 9 N(9, 203)
9 585 snaive 2019 Jan 201 N(201, 1295)
看来我有预测值。但是 accuracy
函数没有生成任何结果,
> accuracy(fc, dt_tsbl)
# A tibble: 9 x 10
.model series.id .type ME RMSE MAE MPE MAPE MASE ACF1
<chr> <int> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 arima 225 Test NaN NaN NaN NaN NaN NaN NA
2 arima 365 Test NaN NaN NaN NaN NaN NaN NA
3 arima 585 Test NaN NaN NaN NaN NaN NaN NA
4 ets 225 Test NaN NaN NaN NaN NaN NaN NA
5 ets 365 Test NaN NaN NaN NaN NaN NaN NA
6 ets 585 Test NaN NaN NaN NaN NaN NaN NA
7 snaive 225 Test NaN NaN NaN NaN NaN NaN NA
8 snaive 365 Test NaN NaN NaN NaN NaN NaN NA
9 snaive 585 Test NaN NaN NaN NaN NaN NaN NA
Warning messages:
1: The future dataset is incomplete, incomplete out-of-sample data will be treated as missing.
1 observation is missing at 2019 Jan
2: 1 error encountered
[1] subscript out of bounds
3: 1 error encountered
[1] subscript out of bounds
4: 1 error encountered
[1] subscript out of bounds
5: 1 error encountered
[1] subscript out of bounds
6: 1 error encountered
[1] subscript out of bounds
7: 1 error encountered
[1] subscript out of bounds
8: 1 error encountered
[1] subscript out of bounds
9: 1 error encountered
[1] subscript out of bounds
10: 1 error encountered
[1] subscript out of bounds
谁能帮我弄清楚这里出了什么问题?
那里有一个使用 forecast
包的 similar post,但它无法帮助我理解为什么我有 NaN
。
如警告消息所示,dt_tsbl
不包含未来观察值 2019 Jan
,因此 样本外 准确度为不可用(NaN
)。
对于样本内精度,accuracy(fit1)
就足够了。
library(tidyverse)
library(tsibble)
library(fable)
fit1 <- dt_tsbl %>%
model(
arima = ARIMA(series.total),
ets = ETS(series.total),
snaive = SNAIVE(series.total),
)
accuracy(fit1)
#> # A tibble: 9 x 10
#> series.id .model .type ME RMSE MAE MPE MAPE MASE ACF1
#> <int> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 225 arima Traini… 6.32 66.6 49.8 -1.14 13.2 0.746 -4.34e-2
#> 2 365 arima Traini… 0.0255 9.76 6.50 -12.9 28.5 0.661 -1.42e-2
#> 3 585 arima Traini… 0.945 30.8 24.6 -1.26 10.3 0.820 1.06e-1
#> 4 225 ets Traini… 1.26 48.8 36.5 -0.983 9.52 0.547 -3.38e-2
#> 5 365 ets Traini… -0.735 8.27 6.18 -10.7 28.0 0.628 7.54e-4
#> 6 585 ets Traini… 0.0185 32.7 25.8 -1.84 10.9 0.861 1.34e-1
#> 7 225 snaive Traini… 21.0 87.5 66.8 3.74 16.0 1.000 3.10e-1
#> 8 365 snaive Traini… -0.625 14.2 9.83 -16.9 44.0 1 3.55e-2
#> 9 585 snaive Traini… 3.25 36.0 30.0 0.323 11.9 1 1.30e-1
由 reprex package (v0.3.0)
于 2019-11-18 创建
要获得样本外准确率,您需要将dt_tsbl
分成训练集和测试集,并将accuracy(fc, dt_tsbl)
替换为accuracy(fc, dt_tsbl_test)
.
我有这个数据,
> dput(dt_tsbl)
structure(list(series.id = c(225L, 225L, 225L, 225L, 225L, 225L,
225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L,
225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L,
225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L,
225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L,
225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L, 225L, 365L,
365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L,
365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L,
365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L,
365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L,
365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L, 365L,
365L, 365L, 365L, 365L, 585L, 585L, 585L, 585L, 585L, 585L, 585L,
585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L,
585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L,
585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L,
585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L,
585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L, 585L), series.total = c(281L,
337L, 397L, 413L, 304L, 295L, 331L, 280L, 471L, 397L, 335L, 165L,
323L, 383L, 400L, 394L, 402L, 562L, 408L, 356L, 509L, 548L, 460L,
367L, 425L, 412L, 416L, 493L, 469L, 372L, 379L, 393L, 482L, 420L,
406L, 298L, 371L, 394L, 436L, 339L, 513L, 401L, 328L, 376L, 525L,
522L, 409L, 333L, 451L, 381L, 477L, 464L, 378L, 422L, 374L, 404L,
438L, 503L, 425L, 299L, 18L, 17L, 15L, 17L, 14L, 23L, 24L, 20L,
45L, 24L, 17L, 13L, 14L, 16L, 24L, 30L, 57L, 29L, 26L, 27L, 30L,
35L, 25L, 20L, 22L, 26L, 28L, 42L, 31L, 31L, 24L, 22L, 64L, 21L,
25L, 22L, 24L, 18L, 15L, 19L, 46L, 23L, 22L, 25L, 21L, 18L, 26L,
14L, 9L, 15L, 18L, 13L, 12L, 17L, 30L, 16L, 22L, 22L, 23L, 20L,
182L, 211L, 298L, 172L, 263L, 248L, 263L, 223L, 282L, 224L, 246L,
189L, 182L, 232L, 272L, 236L, 215L, 301L, 290L, 251L, 263L, 286L,
282L, 266L, 258L, 224L, 239L, 245L, 274L, 261L, 301L, 247L, 234L,
265L, 272L, 230L, 234L, 259L, 242L, 224L, 264L, 229L, 248L, 213L,
288L, 279L, 244L, 239L, 201L, 195L, 212L, 222L, 286L, 246L, 222L,
254L, 339L, 270L, 243L, 267L), mth = structure(c(16071, 16102,
16130, 16161, 16191, 16222, 16252, 16283, 16314, 16344, 16375,
16405, 16436, 16467, 16495, 16526, 16556, 16587, 16617, 16648,
16679, 16709, 16740, 16770, 16801, 16832, 16861, 16892, 16922,
16953, 16983, 17014, 17045, 17075, 17106, 17136, 17167, 17198,
17226, 17257, 17287, 17318, 17348, 17379, 17410, 17440, 17471,
17501, 17532, 17563, 17591, 17622, 17652, 17683, 17713, 17744,
17775, 17805, 17836, 17866, 16071, 16102, 16130, 16161, 16191,
16222, 16252, 16283, 16314, 16344, 16375, 16405, 16436, 16467,
16495, 16526, 16556, 16587, 16617, 16648, 16679, 16709, 16740,
16770, 16801, 16832, 16861, 16892, 16922, 16953, 16983, 17014,
17045, 17075, 17106, 17136, 17167, 17198, 17226, 17257, 17287,
17318, 17348, 17379, 17410, 17440, 17471, 17501, 17532, 17563,
17591, 17622, 17652, 17683, 17713, 17744, 17775, 17805, 17836,
17866, 16071, 16102, 16130, 16161, 16191, 16222, 16252, 16283,
16314, 16344, 16375, 16405, 16436, 16467, 16495, 16526, 16556,
16587, 16617, 16648, 16679, 16709, 16740, 16770, 16801, 16832,
16861, 16892, 16922, 16953, 16983, 17014, 17045, 17075, 17106,
17136, 17167, 17198, 17226, 17257, 17287, 17318, 17348, 17379,
17410, 17440, 17471, 17501, 17532, 17563, 17591, 17622, 17652,
17683, 17713, 17744, 17775, 17805, 17836, 17866), class = c("yearmonth",
"Date"))), row.names = c(NA, -180L), key = structure(list(series.id = c(225L,
365L, 585L), .rows = list(1:60, 61:120, 121:180)), row.names = c(NA,
-3L), class = c("tbl_df", "tbl", "data.frame"), .drop = TRUE), index = structure("mth", ordered = TRUE), index2 = "mth", interval = structure(list(
year = 0, quarter = 0, month = 1, week = 0, day = 0, hour = 0,
minute = 0, second = 0, millisecond = 0, microsecond = 0,
nanosecond = 0, unit = 0), class = "interval"), class = c("tbl_ts",
"tbl_df", "tbl", "data.frame"))
我正在尝试 运行 一些使用寓言包的预测模型,使用以下行,
library(tidyverse)
library(tsibble)
library(fable)
library(fabletools)
fit1 <- dt_tsbl %>%
model(
arima = ARIMA(series.total),
ets = ETS(series.total),
snaive = SNAIVE(series.total),
)
fit1
预测mable
如下,
> fit1
# A mable: 3 x 4
# Key: series.id [3]
series.id arima ets snaive
<int> <model> <model> <model>
1 225 <ARIMA(0,1,2)(1,0,0)[12]> <ETS(A,N,A)> <SNAIVE>
2 365 <ARIMA(1,0,0) w/ mean> <ETS(M,N,M)> <SNAIVE>
3 585 <ARIMA(0,0,0)(0,0,1)[12] w/ mean> <ETS(A,N,N)> <SNAIVE>
我得到了预测值,
> fc
# A fable: 9 x 5 [1M]
# Key: series.id, .model [9]
series.id .model mth series.total .distribution
<int> <chr> <mth> <dbl> <dist>
1 225 arima 2019 Jan 398. N(398, 4748)
2 365 arima 2019 Jan 22.8 N(23, 98)
3 585 arima 2019 Jan 232. N(232, 979)
4 225 ets 2019 Jan 385. N(385, 3101)
5 365 ets 2019 Jan 14.5 N(14, 21)
6 585 ets 2019 Jan 247. N(247, 1103)
7 225 snaive 2019 Jan 451 N(451, 7661)
8 365 snaive 2019 Jan 9 N(9, 203)
9 585 snaive 2019 Jan 201 N(201, 1295)
看来我有预测值。但是 accuracy
函数没有生成任何结果,
> accuracy(fc, dt_tsbl)
# A tibble: 9 x 10
.model series.id .type ME RMSE MAE MPE MAPE MASE ACF1
<chr> <int> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 arima 225 Test NaN NaN NaN NaN NaN NaN NA
2 arima 365 Test NaN NaN NaN NaN NaN NaN NA
3 arima 585 Test NaN NaN NaN NaN NaN NaN NA
4 ets 225 Test NaN NaN NaN NaN NaN NaN NA
5 ets 365 Test NaN NaN NaN NaN NaN NaN NA
6 ets 585 Test NaN NaN NaN NaN NaN NaN NA
7 snaive 225 Test NaN NaN NaN NaN NaN NaN NA
8 snaive 365 Test NaN NaN NaN NaN NaN NaN NA
9 snaive 585 Test NaN NaN NaN NaN NaN NaN NA
Warning messages:
1: The future dataset is incomplete, incomplete out-of-sample data will be treated as missing.
1 observation is missing at 2019 Jan
2: 1 error encountered
[1] subscript out of bounds
3: 1 error encountered
[1] subscript out of bounds
4: 1 error encountered
[1] subscript out of bounds
5: 1 error encountered
[1] subscript out of bounds
6: 1 error encountered
[1] subscript out of bounds
7: 1 error encountered
[1] subscript out of bounds
8: 1 error encountered
[1] subscript out of bounds
9: 1 error encountered
[1] subscript out of bounds
10: 1 error encountered
[1] subscript out of bounds
谁能帮我弄清楚这里出了什么问题?
那里有一个使用 forecast
包的 similar post,但它无法帮助我理解为什么我有 NaN
。
如警告消息所示,dt_tsbl
不包含未来观察值 2019 Jan
,因此 样本外 准确度为不可用(NaN
)。
对于样本内精度,accuracy(fit1)
就足够了。
library(tidyverse)
library(tsibble)
library(fable)
fit1 <- dt_tsbl %>%
model(
arima = ARIMA(series.total),
ets = ETS(series.total),
snaive = SNAIVE(series.total),
)
accuracy(fit1)
#> # A tibble: 9 x 10
#> series.id .model .type ME RMSE MAE MPE MAPE MASE ACF1
#> <int> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 225 arima Traini… 6.32 66.6 49.8 -1.14 13.2 0.746 -4.34e-2
#> 2 365 arima Traini… 0.0255 9.76 6.50 -12.9 28.5 0.661 -1.42e-2
#> 3 585 arima Traini… 0.945 30.8 24.6 -1.26 10.3 0.820 1.06e-1
#> 4 225 ets Traini… 1.26 48.8 36.5 -0.983 9.52 0.547 -3.38e-2
#> 5 365 ets Traini… -0.735 8.27 6.18 -10.7 28.0 0.628 7.54e-4
#> 6 585 ets Traini… 0.0185 32.7 25.8 -1.84 10.9 0.861 1.34e-1
#> 7 225 snaive Traini… 21.0 87.5 66.8 3.74 16.0 1.000 3.10e-1
#> 8 365 snaive Traini… -0.625 14.2 9.83 -16.9 44.0 1 3.55e-2
#> 9 585 snaive Traini… 3.25 36.0 30.0 0.323 11.9 1 1.30e-1
由 reprex package (v0.3.0)
于 2019-11-18 创建要获得样本外准确率,您需要将dt_tsbl
分成训练集和测试集,并将accuracy(fc, dt_tsbl)
替换为accuracy(fc, dt_tsbl_test)
.