generate_fc: Forecasting Engine API

Description Usage Arguments Value Examples

View source: R/fc_models.R

Description

Function which enables the user to select different forecasting algorithms ranging from traditional time series models (i.e. ARIMA, ETS, STL) to machine learning methods (i.e. LSTM, AutoML).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
generate_fc(
  mts_data,
  fc_horizon = 12,
  xreg_data = NULL,
  backtesting_opt = list(use_bt = FALSE, nb_iters = 1, method = c("rolling", "moving"),
    sample_size = c("expanding", "fixed")),
  model_names = c("arima", "ets", "tbats", "bsts", "snaive", "nnetar", "stl",
    "automl_h2o"),
  prepro_fct = NULL,
  models_args = NULL,
  data_dir = NULL,
  time_id = base::Sys.time(),
  nb_threads = 1,
  ...
)

Arguments

mts_data

A univariate or multivariate 'ts', 'mts' or 'xts' object

fc_horizon

An integer, the forecasting horizon (i.e. the number of periods to forecast)

xreg_data

A univariate or multivariate 'ts', 'mts' or 'xts' object, optional external regressors

backtesting_opt

A list, options which define the backtesting approach:

use_bt - A boolean, to determine whether forecasts should be generated on future dates (default) or on past values. Generating forecasts on past dates allows to measure past forecast accuracy and to monitor a statistical model's ability to learn signals from the data.

nb_iters - An integer, to determine the number of forecasting operations to apply (When no backtesting is selected, then only one forecasting exercise is performed)

method - A string, to determine whether to apply a 'rolling' (default) or a 'moving' forecasting window. When 'rolling' is selected, after each forecasting exercise, the forecasting interval increments by one period and drops the last period to include it in the new training sample. When 'moving' is selected, the forecasting interval increments by its size rather than one period.

sample_size - A string, to determine whether the training set size should be 'expanding' (default) or 'fixed'. When 'expanding' is selected, then after each forecasting operation, the periods dropped from the forecasting interval will be added to the training set. When 'fixed' is selected, then adding new periods to the training set will require dropping as many last periods to keep the set's size constant.

model_names

A list or vector of strings representing the model names to be used

prepro_fct

A function, a preprocessing function which handles missing values in the data. The default preprocessing function selects the largest interval of non-missing values and then attributes the most recent dates to those values. Other data handling functions can be applied (e.g. timeSeries::na.contiguous, imputeTS::na.mean, custom-developed...).

models_args

A list, optional arguments to passed to the models

data_dir

A string, directory to which results can be saved as text files

time_id

A POSIXct, timestamp created with Sys.time which is then appended to the results

nb_threads

An integer, the number of threads to use for the automl_h2o model selection process

...

Additional arguments to be passed to the function

Value

A 'tsForecastR' object

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
## Not run: 
library(datasets)

# Generate forecasts on future dates
fc <- generate_fc(AirPassengers,
                  fc_horizon = 12)

fc <- generate_fc(AirPassengers,
                  fc_horizon = 6,
                  model_names = c("arima", "ets",
                                  "lstm_keras",
                                  "automl_h2o"))
fc <- generate_fc(AirPassengers,
                  fc_horizon = 6,
                  model_names = c("ets", "snaive",
                                  "stl", "nnetar"),
                  model_args = list(ets_arg = list(model = "ZZA",
                                                   opt.crit = "amse",
                                                   upper = c(0.3, 0.2,
                                                             0.2, 0.98),
                                    stl_arg = list(s.window = "periodic"))))

# Generate forecasts on past dates to analyze performance
fc <- generate_fc(AirPassengers,
                  model_names = "arima",
                  fc_horizon = 12,
                  backtesting_opt = list(use_bt = TRUE))

# Generate forecasts on past dates with multiple iterations and a rolling window
fc <- generate_fc(AirPassengers,
                  model_names = "tbats",
                  fc_horizon = 6,
                  backtesting_opt = list(use_bt = TRUE,
                                         nb_iters = 6))

## End(Not run)

xavierkamp/tsForecastR documentation built on Feb. 1, 2020, 10:16 a.m.