ModelOriented / shapper

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

Update file to allow plotting of 'id's other than 1 #27

Closed Beirnaert closed 4 years ago

Beirnaert commented 4 years ago

Here is a reproducible example of the error that this proposed fix solves:

Y_train <- HR$status
x_train <- HR[ , -6]
set.seed(123)
model_rf <- randomForest(x = x_train, y = Y_train, ntree = 50)
p_function <- function(model, data) predict(model, newdata = data, type = "prob")

ive_rf <- individual_variable_effect(model_rf, data = x_train, predict_function = p_function,
                                   new_observation = x_train[1:2,], nsamples = 50)

plot(ive_rf, id = 1)
plot(ive_rf, id = 2) # error, this is solved with the propsed fix
Beirnaert commented 4 years ago

This fix still wont work when submitting multiple id's though. Also, maybe consider setting the default id not to 1 but rather to NULL and then set it to the first element in the individual_effect data frame i.e.:

id == NULL

if(is.null(id)){
        id = x$`_id_`[1]
    }
maksymiuks commented 4 years ago

Thanks!