ModelOriented / fairmodels

Flexible tool for bias detection, visualization, and mitigation
https://fairmodels.drwhy.ai/
GNU General Public License v3.0
85 stars 15 forks source link

Error in check_names_in_vector() in helper_functions.R #49

Closed nhward closed 1 year ago

nhward commented 2 years ago

I am getting an error when correctly using "cutoff":

mod1 <- glm(two_year_recid ~ ., data = compas, family = "binomial")
expl7 <- DALEX::explain(mod1, 
                        data = compas, 
                        y = as.numeric(compas$two_year_recid == "Yes"),
                        label = "Thresh", 
                        verbose = FALSE)
fairmodels::fairness_check(expl7,
                        protected = compas$sex,
                        privileged = "Male",
                        cutoff = list("Male" = 0.65, "Female" = 0.5),
                        epsilon = 0.8,
                        colorize = FALSE,
                        verbose = FALSE)   

Error in if (!check_names_in_names_vector(cutoff, protected_levels)) stop("Names of cutoff list does not match levels in protected") : the condition has length > 1

The problem relates to a parameter check. Should the code:

check_names_in_names_vector <- function(x, y) {
   return(names(x) %in% y)
}

not be

check_names_in_names_vector <- function(x, y) {
  return(all(names(x) %in% y))
}
pbiecek commented 2 years ago

Thanks, changed in https://github.com/ModelOriented/fairmodels/commit/6498abf116462bf9afcc46fc0227f88279228d85

nhward commented 1 year ago

Great job