Trains specified model definition(s) to a dataset. This function will
estimate the a set of model definitions (passed via ...
) to each series
within .data
(as identified by the key structure). The result will be a
mable (a model table), which neatly stores the estimated models in a tabular
structure. Rows of the data identify different series within the data, and
each model column contains all models from that model definition. Each cell
in the mable identifies a single model.
model(.data, ...) # S3 method for tbl_ts model(.data, ..., .safely = TRUE)
.data | A data structure suitable for the models (such as a |
---|---|
... | Definitions for the models to be used. All models must share the same response variable. |
.safely | If a model encounters an error, rather than aborting the process a NULL model will be returned instead. This allows for an error to occur when computing many models, without losing the results of the successful models. |
It is possible to estimate models in parallel using the
future package. By specifying a
future::plan()
before estimating the models, they will be computed
according to that plan.
Progress on model estimation can be obtained by wrapping the code with
progressr::with_progress()
. Further customisation on how progress is
reported can be controlled using the progressr
package.
library(fable) library(tsibbledata) # Training an ETS(M,Ad,A) model to Australian beer production aus_production %>% model(ets = ETS(log(Beer) ~ error("M") + trend("Ad") + season("A"))) #> # A mable: 1 x 1 #> ets #> <model> #> 1 <ETS(M,Ad,A)> # Training a seasonal naive and ETS(A,A,A) model to the monthly # "Food retailing" turnover for selected Australian states. library(dplyr) progressr::with_progress( aus_retail %>% filter( Industry == "Food retailing", State %in% c("Victoria", "New South Wales", "Queensland") ) %>% model( snaive = SNAIVE(Turnover), ets = ETS(log(Turnover) ~ error("A") + trend("A") + season("A")), ) ) #> # A mable: 3 x 4 #> # Key: State, Industry [3] #> State Industry snaive ets #> <chr> <chr> <model> <model> #> 1 New South Wales Food retailing <SNAIVE> <ETS(A,A,A)> #> 2 Queensland Food retailing <SNAIVE> <ETS(A,A,A)> #> 3 Victoria Food retailing <SNAIVE> <ETS(A,A,A)>