# NOT RUN {
#
# Regression example (requires randomForest package to run)
#
# Load required packages
library(gridExtra) # for `grid.arrange()`
library(magrittr) # for forward pipe operator `%>%`
library(randomForest)
# Fit a random forest to the Boston housing data
data (boston) # load the boston housing data
set.seed(101) # for reproducibility
boston.rf <- randomForest(cmedv ~ ., data = boston)
# Partial dependence of cmedv on lstat
boston.rf %>%
partial(pred.var = "lstat") %>%
plotPartial(rug = TRUE, train = boston)
# Partial dependence of cmedv on lstat and rm
boston.rf %>%
partial(pred.var = c("lstat", "rm"), chull = TRUE, progress = TRUE) %>%
plotPartial(contour = TRUE, legend.title = "rm")
# ICE curves and c-ICE curves
age.ice <- partial(boston.rf, pred.var = "lstat", ice = TRUE)
p1 <- plotPartial(age.ice, alpha = 0.1)
p2 <- plotPartial(age.ice, center = TRUE, alpha = 0.1)
grid.arrange(p1, p2, ncol = 2)
# }
Run the code above in your browser using DataLab