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

154

Version

0.0.4

License

GPL (>= 2)

Issues

Pull Requests

Stars

Forks

Maintainer

Vitor Cerqueira

Last Published

April 13th, 2018

Functions in tsensembler (0.0.4)

CA.FixedShare_hat

CA generaliser using fixed share
base_ensemble

base_ensemble
base_models_loss

Computing the error of base models
bm_randomforest

Fit Random Forest models
bm_svr

Fit Support Vector Regression models
compute_predictions

Compute the predictions of base models
DETS-class

Dynamic Ensemble for Time Series
DETS

Dynamic Ensemble for Time Series
constructive_aggregation-class

constructive_aggregation-class
get_target

Get the target from a formula
get_top_models

Extract top learners from their weights
EMASE

Weighting Base Models by their Moving Average Squared Error
FIFO

First-In First Out
bm_glm

Fit Generalized Linear Models
bm_mars

Fit Multivariate Adaptive Regression Splines models
combine_predictions

Combining the predictions of several models
committee_set-class

committee_set-class
mae

Computing the mean absolute error
mase

Computing the mean absolute scaled error
CA.OGD_hat

CA generaliser using OGD
erfc

Complementary Gaussian Error Function
meta_rf

Training a random forest arbiter
meta_rf_predict

Arbiter predictions via ranger
ADE-class

Arbitrated Dynamic Ensemble
CA.Ridge_hat

CA generaliser using ridge regression
ae

Computing the absolute error
ADE

Arbitrated Dynamic Ensemble
forecast

Forecasting using an ensemble predictive model
prune_c_contiguity

Prune subsets by contiguity
learning_base_models

Training the base models of an ensemble
best_mvr

Get best PLS/PCR model
blocked_prequential

Prequential Procedure in Blocks
bm_gaussianprocess

Fit Gaussian Process models
base_ensemble-class

base_ensemble-class
prune_c_outperformance

Prune subsets by out-performance
bm_gbm

Fit Generalized Boosted Regression models
sequential_reweighting

Sequential Re-weighting for controlling predictions' redundancy
CA.ADE_hat

CA generaliser using arbitrage
bm_cubist

Fit Cubist models (M5)
sliding_similarity

Sliding similarity via Pearson's correlation
loss_meta_learn

Training an arbiter
constructive_aggregation

Constructive aggregation constructor
CA.EWA_hat

CA generaliser using exponentially weighted average
vcapply

vapply extension for character values
constructive_aggregation_

constructive_aggregation_
viapply

vapply extension for integer values
bm_ffnn

Fit Feedforward Neural Networks models
get_y

Get the response values from a data matrix
ade_hat-class

Predictions by an ADE ensemble
ade_hat

Predictions by an ADE ensemble
build_base_ensemble

Wrapper for creating an ensemble
model_recent_performance

Recent performance of models using EMASE
build_committee_set

Build committee set
bm_pls_pcr

Fit PLS/PCR regression models
bm_ppr

Fit Projection Pursuit Regression models
combine_committees

Merge across sub-ensembles
build_committee

Building a committee for an ADE model
model_specs-class

Setup base learning models
contiguous_count

Contiguity check
mse

Computing the mean squared error
hat_info

Get predict data for generalising
holdout

Holdout
intraining_estimations

Out-of-bag loss estimations
dets_hat-class

Predictions by an DETS ensemble
merging_in_experts

Merge models in each committee
meta_gp_predict

Arbiter predictions via linear model
meta_gp

Training a Gaussian process arbiter
meta_lasso

Training a LASSO arbiter
predict_pls_pcr

predict method for pls/pcr
proportion

Computing the proportions of a numeric vector
meta_lasso_predict

Arbiter predictions via linear model
dets_hat

Predictions by an DETS ensemble
normalize

Scale a numeric vector using max-min
se

Computing the squared error
embed_timeseries

Embedding a Time Series
meta_predict

Predicting loss using arbiter
predict

Predicting new observations using an ensemble
softmax

Computing the softmax
split_by

Splitting expressions by pattern
predict,constructive_aggregation-method

predict method for constructive aggregation
train_ade

Training procedure of for ADE
soft.completion

Soft Imputation
update_ade

Updating an ADE model
select_best

Selecting best model according to weights
intraining_predictions

Out-of-bag predictions
update_ade_meta

Updating the metalearning layer of an ADE model
rmse

Computing the root mean squared error
l1apply

Applying lapply on the rows
tsensembler

Dynamic Ensembles for Time Series Forecasting
roll_mean_matrix

Computing the rolling mean of the columns of a matrix
unlistn

Unlist not using names
water_consumption

Water Consumption in Oporto city (Portugal) area.
model_specs

Setup base learning models
vlapply

vapply extension for logical values
model_weighting

Model weighting
vnapply

vapply extension for numeric values
r_squared

Computing R squared
rbind_l

rbind with do.call syntax
recent_lambda_observations

Get most recent lambda observations
rm.null

List without null elements
update_base_models

Update the base models of an ensemble
update_weights

Updating the weights of base models
CA.MLpol_hat

CA generaliser using polynomial weighted average