使用寓言预测,如何使用特价商品?
Forecasting using fable, how to use specials?
我在使用 fable 包进行预测时尝试使用 specials
,但我无法弄清楚如何使用它们的语法,而且我一直无法找到我可以找到的示例用作指南。
我在下面放了一个简单的例子,尝试将 window 与 MEAN 预测模型一起使用,但它给我一个错误。
非常感谢任何帮助!
# Load libraries
library(fable)
#> Warning: package 'fable' was built under R version 3.6.3
#> Loading required package: fabletools
#> Warning: package 'fabletools' was built under R version 3.6.3
library(tsibble)
#> Warning: package 'tsibble' was built under R version 3.6.3
library(tsibbledata)
#> Warning: package 'tsibbledata' was built under R version 3.6.3
library(lubridate)
#> Warning: package 'lubridate' was built under R version 3.6.3
#>
#> Attaching package: 'lubridate'
#> The following object is masked from 'package:tsibble':
#>
#> interval
#> The following objects are masked from 'package:base':
#>
#> date, intersect, setdiff, union
library(dplyr)
#> Warning: package 'dplyr' was built under R version 3.6.3
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:lubridate':
#>
#> intersect, setdiff, union
#> The following object is masked from 'package:tsibble':
#>
#> id
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
# Run example
aus_retail %>%
filter(
State %in% c("New South Wales", "Victoria"),
Industry == "Department stores"
) %>%
model(
snaive = SNAIVE(Turnover),
mean_f = MEAN(Turnover, window(size = 12))
)
#> Error in hasTsp(x): argument "x" is missing, with no default
由 reprex package (v0.3.0)
于 2020-04-23 创建
sessionInfo()
#> R version 3.6.2 (2019-12-12)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows Server x64 (build 17763)
#>
#> Matrix products: default
#>
#> locale:
#> [1] LC_COLLATE=English_Ireland.1252 LC_CTYPE=English_Ireland.1252
#> [3] LC_MONETARY=English_Ireland.1252 LC_NUMERIC=C
#> [5] LC_TIME=English_Ireland.1252
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] dplyr_0.8.5 lubridate_1.7.8 tsibbledata_0.1.0 tsibble_0.8.6
#> [5] fable_0.1.2 fabletools_0.1.3
#>
#> loaded via a namespace (and not attached):
#> [1] Rcpp_1.0.3 compiler_3.6.2 pillar_1.4.3 highr_0.8
#> [5] tools_3.6.2 digest_0.6.23 evaluate_0.14 lifecycle_0.2.0
#> [9] tibble_3.0.1 gtable_0.3.0 anytime_0.3.7 pkgconfig_2.0.3
#> [13] rlang_0.4.5 yaml_2.2.0 xfun_0.12 stringr_1.4.0
#> [17] knitr_1.27 generics_0.0.2 vctrs_0.2.4 grid_3.6.2
#> [21] tidyselect_1.0.0 glue_1.4.0 R6_2.4.1 rmarkdown_2.1
#> [25] purrr_0.3.4 ggplot2_3.3.0 tidyr_1.0.2 magrittr_1.5
#> [29] scales_1.1.0 ellipsis_0.3.0 htmltools_0.4.0 assertthat_0.2.1
#> [33] colorspace_1.4-1 stringi_1.4.5 munsell_0.5.0 crayon_1.3.4
fable 包使用公式风格的接口进行模型说明,与lm()
功能非常相似。特价商品包含在模型公式的右侧,如果支持多个特价商品,则可以添加它们。而不是 MEAN(Turnover, window(size = 12))
,它应该是 MEAN(Turnover ~ window(size = 12)
。对于 ARIMA()
型号可以有很多特价,您可以使用 ARIMA(Turnover ~ pdq(0,1,4) + PDQ(3,1,0))
.
# Load libraries
library(fable)
library(tsibble)
library(tsibbledata)
library(lubridate)
library(dplyr)
# Run example
aus_retail %>%
filter(
State %in% c("New South Wales", "Victoria"),
Industry == "Department stores"
) %>%
model(
snaive = SNAIVE(Turnover),
mean_f = MEAN(Turnover ~ window(size = 12))
)
#> # A mable: 2 x 4
#> # Key: State, Industry [2]
#> State Industry snaive mean_f
#> <chr> <chr> <model> <model>
#> 1 New South Wales Department stores <SNAIVE> <MEAN>
#> 2 Victoria Department stores <SNAIVE> <MEAN>
由 reprex package (v0.3.0)
于 2020-05-08 创建
我在使用 fable 包进行预测时尝试使用 specials
,但我无法弄清楚如何使用它们的语法,而且我一直无法找到我可以找到的示例用作指南。
我在下面放了一个简单的例子,尝试将 window 与 MEAN 预测模型一起使用,但它给我一个错误。
非常感谢任何帮助!
# Load libraries
library(fable)
#> Warning: package 'fable' was built under R version 3.6.3
#> Loading required package: fabletools
#> Warning: package 'fabletools' was built under R version 3.6.3
library(tsibble)
#> Warning: package 'tsibble' was built under R version 3.6.3
library(tsibbledata)
#> Warning: package 'tsibbledata' was built under R version 3.6.3
library(lubridate)
#> Warning: package 'lubridate' was built under R version 3.6.3
#>
#> Attaching package: 'lubridate'
#> The following object is masked from 'package:tsibble':
#>
#> interval
#> The following objects are masked from 'package:base':
#>
#> date, intersect, setdiff, union
library(dplyr)
#> Warning: package 'dplyr' was built under R version 3.6.3
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:lubridate':
#>
#> intersect, setdiff, union
#> The following object is masked from 'package:tsibble':
#>
#> id
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
# Run example
aus_retail %>%
filter(
State %in% c("New South Wales", "Victoria"),
Industry == "Department stores"
) %>%
model(
snaive = SNAIVE(Turnover),
mean_f = MEAN(Turnover, window(size = 12))
)
#> Error in hasTsp(x): argument "x" is missing, with no default
由 reprex package (v0.3.0)
于 2020-04-23 创建sessionInfo()
#> R version 3.6.2 (2019-12-12)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows Server x64 (build 17763)
#>
#> Matrix products: default
#>
#> locale:
#> [1] LC_COLLATE=English_Ireland.1252 LC_CTYPE=English_Ireland.1252
#> [3] LC_MONETARY=English_Ireland.1252 LC_NUMERIC=C
#> [5] LC_TIME=English_Ireland.1252
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] dplyr_0.8.5 lubridate_1.7.8 tsibbledata_0.1.0 tsibble_0.8.6
#> [5] fable_0.1.2 fabletools_0.1.3
#>
#> loaded via a namespace (and not attached):
#> [1] Rcpp_1.0.3 compiler_3.6.2 pillar_1.4.3 highr_0.8
#> [5] tools_3.6.2 digest_0.6.23 evaluate_0.14 lifecycle_0.2.0
#> [9] tibble_3.0.1 gtable_0.3.0 anytime_0.3.7 pkgconfig_2.0.3
#> [13] rlang_0.4.5 yaml_2.2.0 xfun_0.12 stringr_1.4.0
#> [17] knitr_1.27 generics_0.0.2 vctrs_0.2.4 grid_3.6.2
#> [21] tidyselect_1.0.0 glue_1.4.0 R6_2.4.1 rmarkdown_2.1
#> [25] purrr_0.3.4 ggplot2_3.3.0 tidyr_1.0.2 magrittr_1.5
#> [29] scales_1.1.0 ellipsis_0.3.0 htmltools_0.4.0 assertthat_0.2.1
#> [33] colorspace_1.4-1 stringi_1.4.5 munsell_0.5.0 crayon_1.3.4
fable 包使用公式风格的接口进行模型说明,与lm()
功能非常相似。特价商品包含在模型公式的右侧,如果支持多个特价商品,则可以添加它们。而不是 MEAN(Turnover, window(size = 12))
,它应该是 MEAN(Turnover ~ window(size = 12)
。对于 ARIMA()
型号可以有很多特价,您可以使用 ARIMA(Turnover ~ pdq(0,1,4) + PDQ(3,1,0))
.
# Load libraries
library(fable)
library(tsibble)
library(tsibbledata)
library(lubridate)
library(dplyr)
# Run example
aus_retail %>%
filter(
State %in% c("New South Wales", "Victoria"),
Industry == "Department stores"
) %>%
model(
snaive = SNAIVE(Turnover),
mean_f = MEAN(Turnover ~ window(size = 12))
)
#> # A mable: 2 x 4
#> # Key: State, Industry [2]
#> State Industry snaive mean_f
#> <chr> <chr> <model> <model>
#> 1 New South Wales Department stores <SNAIVE> <MEAN>
#> 2 Victoria Department stores <SNAIVE> <MEAN>
由 reprex package (v0.3.0)
于 2020-05-08 创建