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

resample fails when "protected" does not fully intersect with "y" #48

Closed nhward closed 1 year ago

nhward commented 2 years ago

The following code gives an example whereby I am using interaction() to turn a pair of factors into a single factor. I presume this is allowed and justified. However, if this new factor does not fully intersect with "y", the resample() function fails. By this I mean, that some level of the protected variable does not have both 1 & 0 levels of the "y" variable.

library(fairmodels)
data("compas")
str(compas)
r <- as.numeric(compas$Two_yr_Recidivism)-1
s <- interaction(compas$Sex, compas$Ethnicity) 
table(s)
p_indexes <- fairmodels::resample(protected = s, y = r)

Error in if (expected > actual) { : missing value where TRUE/FALSE needed

If nothing else, a more specific error message is needed, explaining the problem. Preferably, it should continue to generate the best possible resampling.

pbiecek commented 2 years ago

Thanks, one of these groups were too small in size now there are (some) results and warning

nhward commented 1 year ago

Good fix. Well done.