Description Usage Arguments Value Methods and related functions Examples
View source: R/combine_forecasts.R
The horizon-specific models can either be combined to (a) produce final forecasts for only those horizons at which they were trained (i.e., shorter-horizon models override longer-horizon models when producing final short-horizon h-step-ahead forecasts) or (b) produce final forecasts using any combination of horizon-specific models that minimized error over the validation/training dataset.
1 2 3 4 5 6 7 |
... |
One or more objects of class 'forecast_results' from running |
type |
Default: 'horizon'. A character vector of length 1 that identifies the forecast combination method. |
aggregate |
Default |
data_error |
Optional. A list of objects of class 'validation_error' from running |
metric |
Required if |
An S3 object of class 'forecastML' with final h-step-ahead forecasts.
Forecast combination type:
type = 'horizon'
: 1 final h-step-ahead forecast is returned for each model object passed in ...
.
type = 'error'
: 1 final h-step-ahead forecast is returned by selecting, for each forecast horizon,
the model that minimized the chosen error metric at that horizon on the outer-loop validation data sets.
Columns in returned 'forecastML' data.frame:
model
: User-supplied model name in train_model()
.
model_forecast_horizon
: The direct-forecasting time horizon that the model was trained on.
horizon
: Forecast horizons, 1:h, measured in dataset rows.
forecast_period
: The forecast period in row indices or dates. The forecast period starts at either attributes(create_lagged_df())$data_stop + 1
for row indices or attributes(create_lagged_df())$data_stop + 1 * frequency
for date indices.
"groups"
: If given, the user-supplied groups in create_lagged_df()
.
"outcome_name"_pred
: The final forecasts.
"outcome_name"_pred_lower
: If given, the lower forecast bounds returned by the user-supplied prediction function.
"outcome_name"_pred_upper
: If given, the upper forecast bounds returned by the user-supplied prediction function.
The output of combine_forecasts()
has the following generic S3 methods
plot
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 | # Example with "type = 'horizon'".
data("data_seatbelts", package = "forecastML")
horizons <- c(1, 3, 12)
lookback <- 1:15
data_train <- create_lagged_df(data_seatbelts, type = "train", outcome_col = 1,
lookback = lookback, horizon = horizons)
windows <- create_windows(data_train, window_length = 0)
model_function <- function(data, my_outcome_col) {
model <- lm(DriversKilled ~ ., data = data)
return(model)
}
model_results <- train_model(data_train, windows, model_name = "LM", model_function)
data_forecast <- create_lagged_df(data_seatbelts, type = "forecast", outcome_col = 1,
lookback = lookback, horizon = horizons)
prediction_function <- function(model, data_features) {
x <- data_features
data_pred <- data.frame("y_pred" = predict(model, newdata = x))
return(data_pred)
}
data_forecasts <- predict(model_results, prediction_function = list(prediction_function),
data = data_forecast)
data_combined <- combine_forecasts(data_forecasts)
plot(data_combined)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.