# NOT RUN {
# We train a random forest on the Boston dataset:
if (require("rpart")) {
data("Boston", package = "MASS")
rf = rpart(medv ~ ., data = Boston)
mod = Predictor$new(rf, data = Boston)
# Compute the accumulated local effects for all features
eff = FeatureEffects$new(mod)
eff$plot()
# }
# NOT RUN {
# Again, but this time with a partial dependence plot
eff = FeatureEffects$new(mod, method = "pdp")
eff$plot()
# Only a subset of features
eff = FeatureEffects$new(mod, features = c("nox", "crim"))
eff$plot()
# You can access each FeatureEffect individually
eff.nox = eff$effects[["nox"]]
eff.nox$plot()
# FeatureEffects also works with multiclass classification
rf = rpart(Species ~ ., data = iris)
mod = Predictor$new(rf, data = iris, type = "prob")
FeatureEffects$new(mod)$plot(ncol = 2)
# }
# NOT RUN {
}
# }
Run the code above in your browser using DataLab