Learn R Programming

tsensembler (version 0.1.0)

update_weights: Updating the weights of base models

Description

Update the weights of base models of a ADE-class or DETS-class ensemble. This is accomplished by using computing the loss of the base models in new recent observations.

Usage

update_weights(object, newdata)

# S4 method for ADE update_weights(object, newdata)

# S4 method for DETS update_weights(object, newdata)

Arguments

object

a ADE-class or DETS-class model object;

newdata

new data used to update the most recent observations of the time series. At prediction time these observations are used to compute the weights of the base models

See Also

update_weights for the weight updating method for an ADE model, and update_weights for the same method for a DETS model

Other updating models: update_ade_meta(), update_ade()

Examples

Run this code
# NOT RUN {
data("water_consumption")
dataset <- embed_timeseries(water_consumption, 5)

# toy size for checks
train <- dataset[1:300,]
test <- dataset[301:305, ]

specs <- model_specs(c("bm_ppr","bm_glm","bm_mars"), NULL)
## same with model <- DETS(target ~., train, specs)
model <- ADE(target ~., train, specs)

# if consecutive know observations are predicted (e.g. a validation/test set)
# the updating is automatically done internally.
predictions1 <- predict(model, test)@y_hat

# otherwise, the models need to be updated
predictions <- numeric(nrow(test))
# predict new data and update the weights of the model
for (i in seq_along(predictions)) {
  predictions[i] <- predict(model, test[i, ])@y_hat

  model <- update_weights(model, test[i, ])
}

#all.equal(predictions1, predictions)


# }

Run the code above in your browser using DataLab