Skip to content

Instantly share code, notes, and snippets.

@apoorvalal
Created April 18, 2021 07:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apoorvalal/388bdad03120c6197659ee9909cd7a74 to your computer and use it in GitHub Desktop.
Save apoorvalal/388bdad03120c6197659ee9909cd7a74 to your computer and use it in GitHub Desktop.
basic example of pdp / ice / ale
library("iml")
library("randomForest")
data("Boston", package = "MASS")
# %%
rf = randomForest(medv ~ ., data = Boston, ntree = 50)
X = Boston[which(names(Boston) != "medv")]
# %%
model = Predictor$new(rf, data = X, y = Boston$medv)
# %% ALE
effect = FeatureEffects$new(model)
effect$plot()
# %% PDP
pdp <- FeatureEffects$new(model, method = 'pdp')
pdp$plot()
# %%
pdpi <- FeatureEffects$new(model, method = 'pdp+ice')
pdpi$plot()
# %%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment