Learn R Programming

caretEnsemble (version 1.0.0)

predict.caretEnsemble: Make predictions from a caretEnsemble. 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.

Description

Make predictions from a caretEnsemble. 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 class 'caretEnsemble':
predict(object, keepNA = TRUE, se = FALSE,
  return_weights = FALSE, ...)

Arguments

object
a caretEnsemble to make predictions from.
keepNA
a logical indicating whether predictions should be made for all cases where sufficient data exists or only for complete cases across all models. When TRUE this does not predict for missing values. When FALSE, missing values are overwritten with prediction
se
logical, should prediction errors be produced? Default is false.
return_weights
a logical indicating whether prediction weights for each model for each observation should be returend
...
arguments (including newdata) to pass to predict.train. These arguments must be named

Value

  • If return_weights = TRUE a list is returned with a data.frame slot for predictions and a matrix slot for the model weights. If return_weights = FALSE a data.frame is returned for the predictions.

Examples

Run this code
set.seed(42)
models <- caretList(iris[1:50,1:2], iris[1:50,3], methodList=c('glm', 'lm'))
ens <- caretEnsemble(models)
cor(predict(ens, newdata=iris[51:150,1:2]), iris[51:150,3])

Run the code above in your browser using DataLab