Learn R Programming

⚠️There's a newer version (0.1.0) of this package.Take me there.

tsensembler

An S4 package for dynamic combination of forecasting models

Dynamic Ensembles for Time Series Forecasting

The package provided methods for dynamically combining forecasting models for time series forecasting predictive tasks. It leverages machine learning models from other packages to automatically combine expert advice using metalearning and other state-of-the-art forecasting combination approaches.

Installing

Install the package using your R console:

install.packages('tsensembler')

or

devtools::install_github('vcerqueira/tsensembler')

Illustrative examples

# Using data of water consumption time series attached to the package
data("water_consumption")

embedding time series into a matrix
`dataset <- embed_timeseries(water_consumption, 5)`

# splitting data into train/test
train <- dataset[1:1000,]
test <- dataset[1001:1020, ]

# setting up base model parameters
specs <- model_specs(
  learner = c("bm_ppr","bm_glm","bm_svr","bm_mars"), 
  learner_pars = list(
    bm_glm = list(alpha = c(0, .5, 1)),
    bm_svr = list(kernel = c("rbfdot", "polydot"),
                  C = c(1,3)),
    bm_ppr = list(nterms = 4)
  ))

# building the ensemble
model <- ADE(target ~., train, specs)

# forecast next value and update base and meta models
# every three points;
# in the other points, only the weights are updated
predictions <- numeric(nrow(test))
for (i in seq_along(predictions)) {
  predictions[i] <- predict(model, test[i, ])@y_hat
  if (i %% 3 == 0) {
    model <-
      update_base_models(model,
                         rbind.data.frame(train, test[seq_len(i), ]))

    model <- update_ade_meta(model, rbind.data.frame(train, test[seq_len(i), ]))
  }
  else
    model <- update_weights(model, test[i, ])
}

point_forecast <- forecast(model, h = 5)

# setting up an ensemble of support vector machines
specs2 <-
  model_specs(learner = c("bm_svr"),
              learner_pars = list(
                bm_svr = list(kernel = c("vanilladot", "polydot",
                                         "rbfdot"),
                              C = c(1,3,6))
              ))

model <- DETS(target ~., train, specs2)
preds <- predict(model, test)@y_hat

Contact

Any bug report or suggestion please contact me at vitor.cerqueira@fe.up.pt

Copy Link

Version

Install

install.packages('tsensembler')

Monthly Downloads

191

Version

0.0.5

License

GPL (>= 2)

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

July 5th, 2019

Functions in tsensembler (0.0.5)

ADE

Arbitrated Dynamic Ensemble
CA.ADE_hat

CA generaliser using arbitrage
CA.FixedShare_hat

CA generaliser using fixed share
CA.Ridge_hat

CA generaliser using ridge regression
DETS-class

Dynamic Ensemble for Time Series
CA.EWA_hat

CA generaliser using exponentially weighted average
CA.OGD_hat

CA generaliser using OGD
CA.MLpol_hat

CA generaliser using polynomial weighted average
ADE-class

Arbitrated Dynamic Ensemble
base_ensemble-class

base_ensemble-class
DETS

Dynamic Ensemble for Time Series
build_base_ensemble

Wrapper for creating an ensemble
FIFO

First-In First Out
bm_glm

Fit Generalized Linear Models
build_committee

Building a committee for an ADE model
EMASE

Weighting Base Models by their Moving Average Squared Error
bm_gbm

Fit Generalized Boosted Regression models
blocked_prequential

Prequential Procedure in Blocks
ade_hat-class

Predictions by an ADE ensemble
ade_hat

Predictions by an ADE ensemble
bm_arima

Fitting an ARIMA model Using function auto.arima from forecast package
base_models_loss

Computing the error of base models
ae

Computing the absolute error
constructive_aggregation_

constructive_aggregation_
get_target

Get the target from a formula
meta_lasso

Training a LASSO arbiter
constructive_aggregation

Constructive aggregation constructor
forecast

Forecasting using an ensemble predictive model
bm_mars

Fit Multivariate Adaptive Regression Splines models
best_mvr

Get best PLS/PCR model
bm_pls_pcr

Fit PLS/PCR regression models
contiguous_count

Contiguity check
dets_hat-class

Predictions by an DETS ensemble
erfc

Complementary Gaussian Error Function
bm_ffnn

Fit Feedforward Neural Networks models
base_ensemble

base_ensemble
bm_gaussianprocess

Fit Gaussian Process models
bm_svr

Fit Support Vector Regression models
bm_timeseries

Classical time series models
meta_gp

Training a Gaussian process arbiter
meta_predict

Predicting loss using arbiter
ets_predict

Predict function for a model created from bm_ets
meta_gp_predict

Arbiter predictions via linear model
meta_lasso_predict

Arbiter predictions via linear model
bm_ppr

Fit Projection Pursuit Regression models
bm_cubist

Fit Cubist models (M5)
arima_predict

Predict function for a model created from bm_arima
bm_randomforest

Fit Random Forest models
bm_ets

Fitting an Exponential Smoothing model Using function ets from forecast package
compute_predictions

Compute the predictions of base models
bm_xgb

xgb base model
build_committee_set

Build committee set
get_y

Get the response values from a data matrix
get_top_models

Extract top learners from their weights
model_specs-class

Setup base learning models
mse

Computing the mean squared error
model_weighting

Model weighting
constructive_aggregation-class

constructive_aggregation-class
loss_meta_learn

Training an arbiter
merging_in_experts

Merge models in each committee
model_specs

Setup base learning models
predict

Predicting new observations using an ensemble
combine_committees

Merge across sub-ensembles
combine_predictions

Combining the predictions of several models
prune_c_contiguity

Prune subsets by contiguity
sequential_reweighting

Sequential Re-weighting for controlling predictions' redundancy
proportion

Computing the proportions of a numeric vector
sliding_similarity

Sliding similarity via Pearson's correlation
prune_c_outperformance

Prune subsets by out-performance
meta_rf

Training a random forest arbiter
rbind_l

rbind with do.call syntax
predict_pls_pcr

predict method for pls/pcr
water_consumption

Water Consumption in Oporto city (Portugal) area.
vnapply

vapply extension for numeric values
holdout

Holdout
committee_set-class

committee_set-class
hat_info

Get predict data for generalising
train_ade

Training procedure of for ADE
bm_tbats

Fitting an tbats model Using function tbats from forecast package
softmax

Computing the softmax
soft.completion

Soft Imputation
dets_hat

Predictions by an DETS ensemble
update_ade_meta

Updating the metalearning layer of an ADE model
update_base_models

Update the base models of an ensemble
xgb_predict

xgb predict fun
rmse

Computing the root mean squared error
normalize

Scale a numeric vector using max-min
predict,constructive_aggregation-method

predict method for constructive aggregation
roll_mean_matrix

Computing the rolling mean of the columns of a matrix
tsensembler

Dynamic Ensembles for Time Series Forecasting
viapply

vapply extension for integer values
vlapply

vapply extension for logical values
l1apply

Applying lapply on the rows
learning_base_models

Training the base models of an ensemble
meta_rf_predict

Arbiter predictions via ranger
recent_lambda_observations

Get most recent lambda observations
rm.null

List without null elements
model_recent_performance

Recent performance of models using EMASE
embed_timeseries

Embedding a Time Series
se

Computing the squared error
intraining_predictions

Out-of-bag predictions
tbats_predict

Predict function for a model created from bm_tbats
intraining_estimations

Out-of-bag loss estimations
meta_cubist_predict

Arbiter predictions via Cubist
meta_cubist

Training a RBR arbiter
split_by

Splitting expressions by pattern
update_weights

Updating the weights of base models
select_best

Selecting best model according to weights
vcapply

vapply extension for character values
unlistn

Unlist not using names
update_ade

Updating an ADE model