I am getting the following error when trying to execute the following code in section entitled "Replication requirements" (https://uc-r.github.io/iml-pkg):
#classification data
df <- rsample::attrition %>%
mutate_if(is.ordered, factor, ordered = FALSE) %>%
mutate(Attrition = recode(Attrition, "Yes" = "1", "No" = "0") %>% factor(levels = c("1", "0")))
> Error: 'attrition' is not an exported object from 'namespace:rsample'
The problem was solved using the following code:
#data
library(modeldata)
data("attrition", package = "modeldata")
#classification data
df <- attrition %>%
mutate_if(is.ordered, factor, ordered = FALSE) %>%
mutate(Attrition = recode(Attrition, "Yes" = "1", "No" = "0") %>% factor(levels = c("1", "0")))
Unfortunately, I got another error after trying to execute the following code (section entitled "Global interpretation/Feature importance" (https://uc-r.github.io/iml-pkg):
#compute feature importance with specified loss metric
imp.glm <- FeatureImp$new(predictor.glm, loss = "mse")
imp.rf <- FeatureImp$new(predictor.rf, loss = "mse")
imp.gbm <- FeatureImp$new(predictor.gbm, loss = "mse")
> Error in [.data.frame(prediction, , self$class, drop = FALSE) : undefined columns selected
> Error in [.data.frame(prediction, , self$class, drop = FALSE) : undefined columns selected
> Error in [.data.frame(prediction, , self$class, drop = FALSE) : undefined columns selected
I use R 4.2.0/ Win10



You can calculate the variable importance (using the
h2opackage), for yourglmmodel (just choosing one for the example) as follows:h2o::h2o.varimp(glm)Example output:
Does this achieve what you wanted?
Note: I'm assuming you've run all the code up to that point in the link you provided, i.e. that you have created the
glmmodel object using the code provided in the link.