ModelOriented / shapper

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

Strange results for titanic data #13

Closed pbiecek closed 4 years ago

pbiecek commented 5 years ago

Any idea why results for the titanic are so strange?

library("DALEX")
library("randomForest")
load("models/titanic_rf_v6.rda")
load("models/titanic.rda")
explain_titanic_rf <- explain(model = titanic_rf_v6, 
                              data = titanic[,c(1:4,6:8)],
                              y = titanic$survived == "yes", 
                              label = "Random Forest v6")
johny_d <- data.frame(
  class = factor("1st", levels = c("1st", "2nd", "3rd", "deck crew", "engineering crew", 
                                  "restaurant staff", "victualling crew")),
  gender = factor("male", levels = c("female", "male")),
  age = 8,
  sibsp = 0,
  parch = 0,
  fare = 72,
  embarked = factor("Southampton", levels = c("Belfast", "Cherbourg", "Queenstown", "Southampton"))
)

shapper_johny <- shapper::individual_variable_effect(titanic_rf_v6, titanic[,c(1:4,6:8)], DALEX:::yhat.randomForest, johny_d)
plot(shapper_johny)
maksymiuks commented 4 years ago

You have made johny_d with wrong column order, therefore shap returned NA.

We have added exception for such a situation, thanks for that!

pbiecek commented 4 years ago

Thanks, indeed it was the problem. But maybe instead of rising an error you can fix the order of variables, in the same way as it is done for iBreakDown lines 109-112 https://github.com/ModelOriented/iBreakDown/blob/master/R/local_attributions.R#L109 ?

maksymiuks commented 4 years ago

Rising an error fixses a problem when user have made typo.