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

plot_acf error with >2 objects provided #159

Open
michkam89 opened this issue Apr 28, 2022 · 1 comment
Open

plot_acf error with >2 objects provided #159

michkam89 opened this issue Apr 28, 2022 · 1 comment
Labels
invalid ❕ This doesn't seem right

Comments

@michkam89
Copy link

Hi there, I think I found a minor bug in plot_acf() in section creating a dataframe for ggplot.

When providing 3 objects to plot the error occurs:

Error in `f()`:
! Insufficient values in manual scale. 3 needed but only 2 provided.

I think this is connected with the fact that labels column is character not factor and later colours <- rev(theme_drwhy_colors(nlevels(df$label))) returns only 2 colors and the scale is manual and there are three labels. nlevels() returns zero.

Here's my reprex:

library(recipes)
library(workflows)
library(parsnip)
library(DALEX)
library(DALEXtra)

data <- DALEX::titanic_imputed

data$survived <- as.factor(data$survived)

rec <- recipe(survived ~ ., data = data) %>%
  step_normalize(fare)

model_rpart <- decision_tree(tree_depth = 25) %>%
  set_engine("rpart") %>%
  set_mode("classification")

model_lr <- logistic_reg() %>%
  set_engine("glm") |>
  set_mode("classification")

model_svm_ker <- svm_linear() |>
  set_engine("kernlab") |>
  set_mode("classification")

my_models <- list(
  rpart = model_rpart, linear = model_lr, svm = model_svm_ker
)

wflows <- my_models |>
  purrr::map(~ workflow() %>%
        add_recipe(rec) %>%
        add_model(.x))

models_fitted <- wflows |> purrr::map(~ fit(.x, data = data))
#>  Setting default kernel parameters
labels = list(rpart = "rpart", linear = "glm", svm = "svm linear")

explainers <- models_fitted |>
  purrr::map2(
    labels,
    ~ DALEXtra::explain_tidymodels(
      .x,
      data = titanic_imputed,
      y = titanic_imputed$survived,
      label = .y
))
#> Preparation of a new explainer is initiated
#>   -> model label       :  rpart 
#>   -> data              :  2207  rows  8  cols 
#>   -> target variable   :  2207  values 
#>   -> predict function  :  yhat.workflow  will be used (  default  )
#>   -> predicted values  :  No value for predict function target column. (  default  )
#>   -> model_info        :  package tidymodels , ver. 0.1.4 , task classification (  default  ) 
#>   -> predicted values  :  numerical, min =  0.05555556 , mean =  0.3221568 , max =  0.9267399  
#>   -> residual function :  difference between y and yhat (  default  )
#>   -> residuals         :  numerical, min =  -0.9267399 , mean =  1.858834e-17 , max =  0.9444444  
#>   A new explainer has been created!  
#> Preparation of a new explainer is initiated
#>   -> model label       :  glm 
#>   -> data              :  2207  rows  8  cols 
#>   -> target variable   :  2207  values 
#>   -> predict function  :  yhat.workflow  will be used (  default  )
#>   -> predicted values  :  No value for predict function target column. (  default  )
#>   -> model_info        :  package tidymodels , ver. 0.1.4 , task classification (  default  ) 
#>   -> predicted values  :  numerical, min =  0.008128381 , mean =  0.3221568 , max =  0.9731431  
#>   -> residual function :  difference between y and yhat (  default  )
#>   -> residuals         :  numerical, min =  -0.9628583 , mean =  -2.569726e-10 , max =  0.9663346  
#>   A new explainer has been created!  
#> Preparation of a new explainer is initiated
#>   -> model label       :  svm linear 
#>   -> data              :  2207  rows  8  cols 
#>   -> target variable   :  2207  values 
#>   -> predict function  :  yhat.workflow  will be used (  default  )
#>   -> predicted values  :  No value for predict function target column. (  default  )
#>   -> model_info        :  package tidymodels , ver. 0.1.4 , task classification (  default  ) 
#>   -> predicted values  :  numerical, min =  0.1870084 , mean =  0.3221698 , max =  0.7237496  
#>   -> residual function :  difference between y and yhat (  default  )
#>   -> residuals         :  numerical, min =  -0.7236129 , mean =  -1.301819e-05 , max =  0.8128629  
#>   A new explainer has been created!


# debuging auditor
mrs <- purrr::map(explainers, ~ auditor::model_residual(.x))
do.call(auditor::plot_acf, args = unname(mrs))
#> Error in `f()`:
#> ! Insufficient values in manual scale. 3 needed but only 2 provided.
@michkam89
Copy link
Author

btw I already have fix for this, I will propose a PR if you wish.

@hbaniecki hbaniecki added the invalid ❕ This doesn't seem right label Apr 28, 2022
michkam89 pushed a commit to michkam89/auditor that referenced this issue Apr 28, 2022
michkam89 added a commit to michkam89/auditor that referenced this issue Apr 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid ❕ This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants