pricklpitty
pricklpitty

Reputation: 1

How to create a 2D partial dependence plot on a trained random forest model using the iml package in R?

I have trained randomForest models using the mlr3 package in R and successfully used the iml package to create 1D plots of partial dependence (PDP) and accumulated local effects (ALE) to interpret the trained ML models. I have seen that it is possible to create 2D plots using iml package from the book Interpretable Machine Learning (here) in which it is written that iml package was used therein (unfortunately, code seems to not be provided). However, I can really not find how to create a 2D plot (e.g. which function/argument to use) and could not find any 2D code example.

Here is my example code which creates a 1D plot (mainly from the iml manual).

library("randomForest") 
library("iml")

# Train a random forest regression on the Boston dataset:  
data("Boston", package = "MASS")  
rf <- randomForest(medv ~ ., data = Boston, ntree = 50) 
mod <- Predictor$new(rf, data = Boston) 

# PDP
eff <- FeatureEffects$new(mod, method="pdp")
eff$plot(features = c("lstat","rm"))

# ALE
eff <- FeatureEffects$new(mod, method="ale")
eff$plot(features = c("lstat","rm"))

Upvotes: 0

Views: 264

Answers (0)

Related Questions