Manually setting weights for a combination model in fable

Hi everyone. I'm working with the fable package to create a combination model. In the documentation, the default argument for the weights for each model within the combination are set to equal. I'm looking for advice on a way to customize the weights manually instead (for example, to have the SNAIVE model weight equal to 0.3 below, and then the TSLM model equal to 0.7).

library(fable)
library(tsibble)
library(tsibbledata)

aus_production %>%
  model(
    cmbn1 = combination_model(
      SNAIVE(Beer), TSLM(Beer ~ trend() + season()), 
      cmbn_args = list(weights = "equal")
    )
  )

I've added a couple of features to make arbitrary combinations of models easier:

  1. combination_weighted() is like combination_ensemble() but allows for arbitrary weights.
    It can be used with:
library(fable)
#> Loading required package: fabletools
library(tsibble)
#> 
#> Attaching package: 'tsibble'
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, union
library(tsibbledata)

aus_production %>%
  model(
    cmbn1 = combination_model(
      SNAIVE(Beer), TSLM(Beer ~ trend() + season()), 
      cmbn_fn = combination_weighted,
      cmbn_args = list(weights = c(0.3, 0.7))
    )
  )
#> # A mable: 1 x 1
#>           cmbn1
#>         <model>
#> 1 <COMBINATION>

Created on 2021-08-02 by the reprex package (v2.0.0)

  1. Improved response variable simplification for combination models. This allows you to write arbitrary expressions like:
library(fable)
#> Loading required package: fabletools
library(tsibble)
#> 
#> Attaching package: 'tsibble'
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, union
library(tsibbledata)

aus_production %>%
  model(
    snaive = SNAIVE(Beer), 
    tslm = TSLM(Beer ~ trend() + season())
  ) %>% 
  dplyr::transmute(cmbn1 = 0.3 * snaive + 0.7 * tslm)
#> # A mable: 1 x 1
#>           cmbn1
#>         <model>
#> 1 <COMBINATION>

Created on 2021-08-02 by the reprex package (v2.0.0)

You will need the development version of fabletools to try these features out (version >=0.3.1.9000), which can be installed with remotes::install_github("tidyverts/fabletools")

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.