ModelOriented / iBreakDown

Break Down with interactions for local explanations (SHAP, BreakDown, iBreakDown)
https://ModelOriented.github.io/iBreakDown/
GNU General Public License v3.0
81 stars 15 forks source link

plot() gives BD profiles for all target classes #87

Closed AtharKharal closed 4 years ago

AtharKharal commented 4 years ago

In a multiclass usecase, one needs BreakDown profile for only one target class, however plot() produces profiles for ALL target classes. How to control plot() to show only required target class result. Here is a dummy code similar to my actual usecase. I need to see BD plot for "DF lrnr exp.alpha" only and two other should not be shown. This kind of selection is needed where number of target classes and/or number of variables is large. Here is the dummy code: `library(DALEX) library(DALEXtra) library(tidyverse) library("mlr3verse")

df=data.frame(w=c(34,65,23,78,37, 34,65,23,78,37, 34,65,23,78,37, 34,65,23,78,37), x=c('a','b','a','c','c', 'a','b','a','c','c', 'a','b','a','c','c', 'a','b','a','c','c'), y=c(TRUE,FALSE,TRUE,TRUE,FALSE, TRUE,FALSE,TRUE,TRUE,FALSE, TRUE,FALSE,TRUE,TRUE,FALSE, TRUE,FALSE,TRUE,TRUE,FALSE), z=c('alpha','alpha','delta','delta','phi', 'alpha','alpha','delta','delta','phi', 'alpha','alpha','delta','delta','phi', 'alpha','alpha','delta','delta','phi') )

df_task <- TaskClassif$new(id = "my_df", backend = df, target = "z") df_lrn <- lrn("classif.rpart", predict_type = "prob") df_lrn$train(df_task)

df_lrn_exp <- explain_mlr3(df_lrn, data = df[,-4], y = df$z, label = "DF lrnr exp") df_BD <- predict_parts(df_lrn_exp, df[3,], type='break_down') plot(df_BD, max_features = 5, add_contributions = T) `

pbiecek commented 4 years ago

Hi, the easiest solution would be to manually filter out only lables that are needed from the break down object

here is an example

df_BD <- predict_parts(df_lrn_exp, df[3,], type='break_down')

# leave only 'DF lrnr exp.alpha'
df_BD <- df_BD[df_BD$label == "DF lrnr exp.alpha",]

plot(df_BD, max_features = 5, add_contributions = T)
AtharKharal commented 4 years ago

thanks indeed