我正在尝试使用 R
fable
和/或 fable.tools
包创建组合模型。但是,我想使用中位数而不是平均值。
我找不到任何使用 cmbn_fn 或 cmbn_args 的示例,但它不是均值或加权的,但我认为这一定是可能的。
我尝试了类似下面的多种变体,但没有成功。希望有人知道如何返回模型的中位数。
comb1 = combination_model(
TSLM(log(y) ~ trend() + season()),
ARIMA(log(y), stepwise = TRUE, approximation = TRUE)),
THETA(log(y)),
ETS(log(y)),
cmbn_fn = combination_ensemble,
cmbn_args = list(median)
谢谢你, 布莱恩
如果组合的分量模型不是正态分布,您可以从自举路径获得组合模型的中值预测。 我需要对 fabletools 进行一些小小的添加才能实现这一点,因此您需要使用
remotes::install_github("tidyverts/fabletools")
从 GitHub 安装最新的开发版本。
以下是其工作原理的示例。
library(fable)
#> Loading required package: fabletools
tsibbledata::aus_production %>%
model(
cmbn1 = combination_model(
SNAIVE(log(Beer)), TSLM(log(Beer) ~ trend() + season()),
cmbn_args = list(weights = "inv_var")
)
) |>
forecast(bootstrap = TRUE, point_forecast = list(.mean = mean, .median = median))
#> # A fable: 8 x 5 [1Q]
#> # Key: .model [1]
#> .model Quarter Beer .mean .median
#> <chr> <qtr> <dist> <dbl> <dbl>
#> 1 cmbn1 2010 Q3 sample[5000] 425. 425.
#> 2 cmbn1 2010 Q4 sample[5000] 497. 497.
#> 3 cmbn1 2011 Q1 sample[5000] 423. 423.
#> 4 cmbn1 2011 Q2 sample[5000] 381. 381.
#> 5 cmbn1 2011 Q3 sample[5000] 425. 424.
#> 6 cmbn1 2011 Q4 sample[5000] 498. 498.
#> 7 cmbn1 2012 Q1 sample[5000] 423. 423.
#> 8 cmbn1 2012 Q2 sample[5000] 382. 381.
创建于 2023-10-18,使用 reprex v2.0.2
请注意,
cmbn_args
是传递给cmbn_fn
的参数,它不接受中位数作为输入。这适用于诸如组合的自定义权重之类的事情。要生成的点预测在 point_forecast
函数的 forecast()
参数中指定。