
Last chance! 50% off unlimited learning
Sale ends in
Predict the response for newdata of a TreeSurrogate object.
# S3 method for TreeSurrogate
predict(object, newdata, type = "prob", ...)
The surrogate tree. A TreeSurrogate R6 object
A data.frame for which to predict
Either "prob" or "class". Ignored if the surrogate tree does regression.
Further argumets for predict_party
A data.frame with the predicted outcome.
In case of regression it is the predicted
This function makes the TreeSurrogate object call its iternal object$predict() method.
# NOT RUN {
if (require("randomForest")) {
# Fit a Random Forest on the Boston housing data set
data("Boston", package = "MASS")
rf = randomForest(medv ~ ., data = Boston, ntree = 50)
# Create a model object
mod = Predictor$new(rf, data = Boston[-which(names(Boston) == "medv")])
# Fit a decision tree as a surrogate for the whole random forest
dt = TreeSurrogate$new(mod)
# Plot the resulting leaf nodes
predict(dt, newdata = Boston)
}
# }
Run the code above in your browser using DataLab