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

Local attributions plot too wide due to unrounded model values #68

Closed agilebean closed 4 years ago

agilebean commented 4 years ago

For regressions, the table returned by local_attributions() contains values that are not rounded (left column):

                                             contribution
rf  model: intercept                                4.085
rf  model: joy = 0                                 -0.539
rf  model: negative = 0.5                          -0.380
rf  model: disgust = 0.214285714285714             -0.684

This would not be an issue, however, the plot becomes too wide which narrows the main plot: image

Is there any way to round the decimal values in the y-axis?

pbiecek commented 4 years ago

Thansk, very important point, can you give a reproducible example?

We are using the iBreakDown::nice_format to round values (by default with signif(,4)). and I cannot reproduce this problem because numerics are rounded in examples that I've tried/

pbiecek commented 4 years ago

By default names are rounded with signif(,4), but now you can overwrite labels with the vnames argument see https://github.com/ModelOriented/iBreakDown/commit/b2e96a0ed6ce271e49f0dec8d30a8365e6e30710

agilebean commented 4 years ago

It would still be great if the labels could be created automatically without using vnames. I prepared a reproducible example with this model

Please use it like this:

models.list.short <- readRDS("models.list.short.rds")
model.rf <- models.list.short$rf

local.obs <- models.list.short$testing.set %>% 
    # filter(reviews.rating != 5 & reviews.rating != 4) %>% 
    filter(reviews.rating == TARGET.VALUE) %>% 
    select(-reviews.rating) %>% 
    sample_n(5) 

DALEX.explainer <- DALEX::explain(
   model = model.rf,
   data = features,
   y = target == TARGET.VALUE,
   label = paste(model_object$method, " model"),
   colorize = TRUE
  )

DALEX.attribution <- DALEX.explainer %>%
   iBreakDown::local_attributions(
      local.obs,
      keep_distributions = TRUE
  )

DALEX.attribution.plot <- DALEX.attribution %>% 
    plot(
        digits = 3,
        shift_contributions = 0.03
    ) %>% print

I just used it and still got the unrounded figures image

pbiecek commented 4 years ago

@agilebean for some strange reason the problem comes from local.obs being a tibble. this will work properly with local.obs converted to data.frame

DALEX.attribution <- DALEX.explainer %>%
     iBreakDown::local_attributions(
         as.data.frame(local.obs),
         keep_distributions = TRUE
     )
Screenshot 2020-02-20 at 10 08 19 AM
agilebean commented 4 years ago

That is truly unexpected. Thanks for finding that out!!

pbiecek commented 4 years ago

It's because for tibbles the local.obs[1,1] is not numeric (it's still tilbble) so iBreakDown does not know how to prettify and treats these values as characters