Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
agilebean opened this issue Feb 3, 2020 · 6 comments
Closed

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

agilebean opened this issue Feb 3, 2020 · 6 comments
Labels
feature 💡 New feature or enhancement request
Milestone

Comments

@agilebean
Copy link

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
Copy link
Member

pbiecek commented Feb 15, 2020

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 added a commit that referenced this issue Feb 15, 2020
@pbiecek
Copy link
Member

pbiecek commented Feb 17, 2020

By default names are rounded with signif(,4),
but now you can overwrite labels with the vnames argument
see b2e96a0

@pbiecek pbiecek closed this as completed Feb 17, 2020
@agilebean
Copy link
Author

agilebean commented Feb 20, 2020

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
Copy link
Member

pbiecek commented Feb 20, 2020

@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
Copy link
Author

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

@pbiecek
Copy link
Member

pbiecek commented Feb 20, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature 💡 New feature or enhancement request
Projects
None yet
Development

No branches or pull requests

2 participants