Learn R Programming

caretEnsemble (version 2.0.3)

predict.caretStack: Make predictions from a caretStack

Description

Make predictions from a caretStack. This function passes the data to each function in turn to make a matrix of predictions, and then multiplies that matrix by the vector of weights to get a single, combined vector of predictions.

Usage

# S3 method for caretStack
predict(
  object,
  newdata = NULL,
  se = FALSE,
  level = 0.95,
  return_weights = FALSE,
  na.action = na.omit,
  ...
)

Arguments

object

a caretStack to make predictions from.

newdata

a new dataframe to make predictions on

se

logical, should prediction errors be produced? Default is false.

level

tolerance/confidence level

return_weights

a logical indicating whether prediction weights for each model should be returned

na.action

the method for handling missing data passed to predict.train.

...

arguments to pass to predict.train.

Details

Prediction weights are defined as variable importance in the stacked caret model. This is not available for all cases such as where the library model predictions are transformed before being passed to the stacking model.

Examples

Run this code
if (FALSE) {
library("rpart")
models <- caretList(
  x=iris[1:100,1:2],
  y=iris[1:100,3],
  trControl=trainControl(method="cv"),
  methodList=c("rpart", "glm")
)
meta_model <- caretStack(models, method="lm")
RMSE(predict(meta_model, iris[101:150,1:2]), iris[101:150,3])
}

Run the code above in your browser using DataLab