Learn R Programming

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

nall_kernels <- c("rbfdot","polydot","vanilladot","laplacedot")

pars_predictors <- list(
  bm_gaussianprocess = list(kernel = nall_kernels, tol = c(.001)),
  bm_svr = list(kernel = nall_kernels, C=c(1, 5), epsilon=c(.1,0.01)),
  bm_ppr = list(nterms = c(2,4),
                sm.method = c("supsmu","gcvspline")),
  bm_mars = list(degree = c(1, 3), nk = c(10,20),
                 thresh=c(0.001),
                 pmethod=c("forward")),
  bm_glm = list(alpha = c(0,.25,.5,.75,1),
                family = c("gaussian")),
  bm_randomforest = list(num.trees = c(250,500),
                         mtry = c(5,10)),
  bm_pls_pcr = list(method = c("simpls","kernelpls","svdpc")),
  bm_cubist  = list(committees= c(1,5, 15)),
  bm_xgb = list()
)


base_predictors <- names(pars_predictors)

specs <- model_specs(base_predictors,pars_predictors)

# building the ensemble
model <- quickADE(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, ])
}


# 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.1.0

License

GPL (>= 2)

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

October 27th, 2020

Functions in tsensembler (0.1.0)

DETS

Dynamic Ensemble for Time Series
ae

Computing the absolute error
base_ensemble

base_ensemble
ADE

Arbitrated Dynamic Ensemble
ade_hat-class

Predictions by an ADE ensemble
base_ensemble-class

base_ensemble-class
EMASE

Weighting Base Models by their Moving Average Squared Error
ade_hat

Predictions by an ADE ensemble
DETS-class

Dynamic Ensemble for Time Series
ADE-class

Arbitrated Dynamic Ensemble
bm_ffnn

Fit Feedforward Neural Networks models
bm_ppr

Fit Projection Pursuit Regression models
bm_gaussianprocess

Fit Gaussian Process models
bm_randomforest

Fit Random Forest models
get_target

Get the target from a formula
embed_timeseries

Embedding a Time Series
meta_ffnn

Training a Gaussian prosadacess arbiter
meta_ffnn_predict

Arbiter predictions via linear ssmodel
bm_gbm

Fit Generalized Boosted Regression models
dets_hat-class

Predictions by an DETS ensemble
best_mvr

Get best PLS/PCR model
base_models_loss

Computing the error of base models
bm_glm

Fit Generalized Linear Models
meta_xgb

Training a xgb arbiter
combine_predictions

Combining the predictions of several models
dets_hat

Predictions by an DETS ensemble
meta_svr_predict

Arbiter predictions via linear model
predict_pls_pcr

predict method for pls/pcr
blocked_prequential

Prequential Procedure in Blocks
compute_predictions

Compute the predictions of base models
bm_cubist

Fit Cubist models (M5)
build_base_ensemble

Wrapper for creating an ensemble
bm_svr

Fit Support Vector Regression models
get_top_models

Extract top learners from their weights
bm_mars

Fit Multivariate Adaptive Regression Splines models
bm_pls_pcr

Fit PLS/PCR regression models
bm_xgb

Base model for XGBoost
holdout

Holdout
meta_lasso

Training a LASSO arbiter
meta_lasso_predict

Arbiter predictions via linear model
proportion

Computing the proportions of a numeric vector
meta_xgb_predict

Arbiter predictions via xgb
intraining_estimations

Out-of-bag loss estimations
meta_mars

Training a meta_mars process arbiter
intraining_predictions

Out-of-bag predictions
l1apply

Applying lapply on the rows
meta_gp

Training a Gaussian process arbiter
get_y

Get the response values from a data matrix
meta_mars_predict

Arbiter predictions via mars model
meta_rf

Training a random forest arbiter
meta_gp_predict

Arbiter predictions via linear model
meta_predict

Predicting loss using arbiter
meta_pls

Training a pls process arbiter
meta_ppr

Training a meta_mars process arbiter
select_best

Selecting best model according to weights
xgb_predict_

asdasd
update_base_models

Update the base models of an ensemble
update_weights

Updating the weights of base models
model_recent_performance

Recent performance of models using EMASE
se

Computing the squared error
xgb_predict

XGBoost predict function
sequential_reweighting

Sequential Re-weighting for controlling predictions' redundancy
sliding_similarity

Sliding similarity via Pearson's correlation
meta_pls_predict

Arbiter predictions via pls model
meta_ppr_predict

Arbiter predictions via ppr model
normalize

Scale a numeric vector using max-min
model_weighting

Model weighting
rmse

Computing the root mean squared error
xgb_optimizer

XGB optimizer
model_specs-class

Setup base learning models
mse

Computing the mean squared error
water_consumption

Water Consumption in Oporto city (Portugal) area.
roll_mean_matrix

Computing the rolling mean of the columns of a matrix
model_specs

Setup base learning models
predict

Predicting new observations using an ensemble
learning_base_models

Training the base models of an ensemble
build_committee

Building a committee for an ADE model
rbind_l

rbind with do.call syntax
loss_meta_learn

Training an arbiter
train_ade_quick

ADE training poor version Train meta-models in the training data, as opposed to using a validation dataset
update_ade

Updating an ADE model
update_ade_meta

Updating the metalearning layer of an ADE model
tsensembler

Dynamic Ensembles for Time Series Forecasting
recent_lambda_observations

Get most recent lambda observations
meta_cubist

Training a RBR arbiter
softmax

Computing the softmax
meta_cubist_predict

Arbiter predictions via Cubist
soft.completion

Soft Imputation
split_by

Splitting expressions by pattern
meta_rf_predict

Arbiter predictions via ranger
train_ade

Training procedure of for ADE
meta_svr

Training a Gaussian process arbiter