update_base_models {tsensembler} | R Documentation |
Update the base models of an ensemble
Description
This is a generic function for updating the base models comprising an ensemble.
Usage
update_base_models(object, newdata, num_cores = 1)
## S4 method for signature 'ADE'
update_base_models(object, newdata, num_cores = 1)
## S4 method for signature 'DETS'
update_base_models(object, newdata, num_cores = 1)
Arguments
object |
an ensemble object, of class |
newdata |
new data used to update the models. Each base model
is retrained, so |
num_cores |
A numeric value to specify the number of cores used to train base and meta models. num_cores = 1 leads to sequential training of models. num_cores > 1 splits the training of the base models across num_cores cores. |
Details
update_base_models function receives a model object and a new dataset for retraining the base models. This new data should have the same structure as the one used to build the ensemble.
See Also
ADE-class
for the ADE model information, and
DETS-class
for the DETS model information;
update_ade_meta
for updating the meta models of an ADE ensemble.
See update_weights
for the method used to update
the weights of the ensemble. Updating the weights only changes the information
about the recent observations for computing the weights of the base models,
while updating the model uses that information to retrain the models.
Examples
data("water_consumption")
dataset <- embed_timeseries(water_consumption, 5)
# toy size for checks execution time
train <- dataset[1:300,]
test <- dataset[301:305, ]
specs <- model_specs(c("bm_ppr","bm_glm","bm_mars"), NULL)
model <- ADE(target ~., train, specs)
predictions <- numeric(nrow(test))
for (i in seq_along(predictions)) {
predictions[i] <- predict(model, test[i, ])@y_hat
model <-
update_base_models(model,
rbind.data.frame(train, test[seq_len(i), ]))
}
####
specs2 <- model_specs(c("bm_ppr","bm_randomforest","bm_svr"), NULL)
modeldets <- DETS(target ~., train, specs2)
predictions <- numeric(nrow(test))
# predict new data and update models every three points
# in the remaining points, the only the weights are updated
for (i in seq_along(predictions)) {
predictions[i] <- predict(modeldets, test[i, ])@y_hat
if (i %% 3 == 0)
modeldets <-
update_base_models(modeldets,
rbind.data.frame(train, test[seq_len(i), ]))
else
modeldets <- update_weights(modeldets, test[seq_len(i), ])
}