predict.TreeSurrogate: Predict Tree Surrogate

View source: R/TreeSurrogate.R

predict.TreeSurrogateR Documentation

Predict Tree Surrogate

Description

Predict the response for newdata of a TreeSurrogate object.

This function makes the TreeSurrogate object call its internal ⁠$predict()⁠ method.

Usage

## S3 method for class 'TreeSurrogate'
predict(object, newdata, type = "prob", ...)

Arguments

object

The surrogate tree. A TreeSurrogate object.

newdata

A data.frame for which to predict.

type

Either "prob" or "class". Ignored if the surrogate tree does regression.

...

Further arguments for predict_party.

Value

A data.frame with the predicted outcome. In case of regression it is the predicted \hat{y}. In case of classification it is either the class probabilities (for type "prob") or the class label (type "class")

See Also

TreeSurrogate

Examples

library("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)

iml documentation built on May 29, 2024, 1:59 a.m.