ModelOriented / shapper

An R wrapper of SHAP python library
https://modeloriented.github.io/shapper/
58 stars 16 forks source link

Examples with DALEX2 wrappers #2

Closed pbiecek closed 5 years ago

pbiecek commented 5 years ago

Any idea why this is not working?

# load datasets
library("DALEX2")
Y_train <- HR$status
x_train <- HR[ , -6]
x_train$gender <- as.numeric(x_train$gender)

# Let's build a model
library("randomForest")
set.seed(123)
model_rf <- randomForest(x = x_train, y = Y_train)

# here DALEX starts
library("DALEX2")
rf_explainer <- explain(model_rf, data = x_train)

# here shapper starts
library("shapper")
ive <- individual_variable_effect(rf_explainer,
                               new_observation = x_train[1,])

plot(ive)
agosiewska commented 5 years ago

Yes, previously I've fixed names of parameters for predict_function as x and data. Now it should work for any names.

agosiewska commented 5 years ago

Now it works even without converting factors into numeric vectors

# load datasets
library("DALEX2")
Y_train <- HR$status
x_train <- HR[ , -6]

# Let's build a model
library("randomForest")
set.seed(123)
model_rf <- randomForest(x = x_train, y = Y_train)

# here DALEX starts
library("DALEX2")
rf_explainer <- explain(model_rf, data = x_train)

# here shapper starts
library("shapper")
ive <- individual_variable_effect(rf_explainer,
                                  new_observation = x_train[1,])

plot(ive)