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 vmac@inesctec.pt

Copy Link

Version

Install

install.packages('tsensembler')

Monthly Downloads

154

Version

0.0.2

License

GPL (>= 2)

Issues

Pull Requests

Stars

Forks

Maintainer

Vitor Cerqueira

Last Published

August 28th, 2017

Functions in tsensembler (0.0.2)

ade_hat-class

Predictions by an ADE ensemble
ade_hat

Predictions by an ADE ensemble
ae

Computing the absolute error
base_ensemble-class

base_ensemble-class
ADE-class

Arbitrated Dynamic Ensemble
ADE

Arbitrated Dynamic Ensemble
EMASE

Weighting Base Models by their Moving Average Squared Error
FIFO

First-In First Out
DETS-class

Dynamic Ensemble for Time Series
DETS

Dynamic Ensemble for Time Series
bm_glm

Fit Generalized Linear Models
bm_mars

Fit Multivariate Adaptive Regression Splines models
bm_pls_pcr

Fit PLS/PCR regression models
bm_ppr

Fit Projection Pursuit Regression models
best_mvr

Get best PLS/PCR model
blocked_prequential

Prequential Procedure in Blocks
combine_predictions

Combining the predictions of several models
compute_predictions

Compute the predictions of base models
get_top_models

Extract top learners from their weights
base_ensemble

base_ensemble
base_models_loss

Computing the error of base models
dets_hat-class

Predictions by an DETS ensemble
dets_hat

Predictions by an DETS ensemble
bm_cubist

Fit Cubist models (M5)
bm_ffnn

Fit Feedforward Neural Networks models
build_base_ensemble

Wrapper for creating an ensemble
get_y

Get the response values from a data matrix
model_specs

Setup base learning models
model_weighting

Model weighting
r_squared

Computing R squared
rbind_l

rbind with do.call syntax
build_committee

Building a committee for an ADE model
intraining_estimations

Out-of-bag loss estimations
intraining_predictions

Out-of-bag predictions
predict

Predicting new observations using an ensemble
bm_gaussianprocess

Fit Gaussian Process models
bm_gbm

Fit Generalized Boosted Regression models
bm_randomforest

Fit Random Forest models
bm_svr

Fit Support Vector Regression models
forecast

Forecasting using an ensemble predictive model
proportion

Computing the proportions of a numeric vector
unlistn

Unlist not using names
update_ade

Updating an ADE model
vnapply

vapply extension for numeric values
water_consumption

Water Consumption in Oporto city (Portugal) area.
softmax

Computing the softmax
split_by

Splitting expressions by pattern
viapply

vapply extension for integer values
embed_timeseries

Embedding a Time Series
erfc

Complementary Gaussian Error Function
model_recent_performance

Recent performance of models using EMASE
model_specs-class

Setup base learning models
l1apply

Applying lapply on the rows
learning_base_models

Training the base models of an ensemble
mse

Computing the mean squared error
normalize

Scale a numeric vector using max-min
recent_lambda_observations

Get most recent lambda observations
rm.null

List without null elements
update_weights

Updating the weights of base models
se

Computing the squared error
select_best

Selecting best model according to weights
update_ade_meta

Updating the metalearning layer of an ADE model
update_base_models

Update the base models of an ensemble
vlapply

vapply extension for logical values
get_target

Get the target from a formula
mae

Computing the mean absolute error
mase

Computing the mean absolute scaled error
rmse

Computing the root mean squared error
roll_mean_matrix

Computing the rolling mean of the columns of a matrix
train_ade

Training procedure of for ADE
tsensembler

Dynamic Ensembles for Time Series Forecasting
vcapply

vapply extension for character values