library(randomForest)
library(pdp)
data(boston)
set.seed(42)
rf <- randomForest(cmedv ~ ., data = boston)
data <- boston[,-3] # remove target variable
ntrees <- c(4,8,16,32,64,128)
xg <- xgrove(rf, data, ntrees)
xg
plot(xg)
# Example of a classification problem using the iris data.
# A predict function has to be defined, here for the posterior probabilities of the class Virginica.
data(iris)
set.seed(42)
rf <- randomForest(Species ~ ., data = iris)
data <- iris[,-5] # remove target variable
pf <- function(model, data){
predict(model, data, type = "prob")[,3]
}
xgrove(rf, data, pfun = pf)
Run the code above in your browser using DataLab