| predict.wrap_caret | R Documentation |
Predict method for mlS3 caret wrapper
## S3 method for class 'wrap_caret'
predict(object, newx, type = NULL, ...)
object |
Object from wrap_caret |
newx |
New features (matrix or data frame) |
type |
Prediction type: "raw" (default), "class", "prob", or NULL |
... |
Additional arguments to caret::predict.train |
Vector or matrix of predictions
# Only runs if caret is installed
data(mtcars)
# Prepare data
X_reg <- mtcars[, -1] # All except mpg
y_reg <- mtcars$mpg # Target variable
# Split into train/test
set.seed(123)
idx_reg <- sample(nrow(X_reg), 0.7 * nrow(X_reg))
X_train <- X_reg[idx_reg, ]
y_train <- y_reg[idx_reg]
X_test <- X_reg[-idx_reg, ]
y_test <- y_reg[-idx_reg]
mod <- wrap_caret(X_train, y_train, method = "rf", mtry = 3)
(pred <- predict(mod, X_test))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.