Package: bias-detector
Bias DetectorBias Detector is a python package for detecting gender/race bias in binary classification models.Based on first and last name/zip code the package analyzes the probability of the user belonging to different genders/races. Then, the model predictions per gender/race are compared using various bias metrics.Using this package you will be able to gain insight into whether your model is biased or not, and if so, how much bias was found.The Bias Detector is based on statistical data from the US, and therefore it performs best with US originated data. However, it is possible to optimize the package for other countries by adding the relevant statistical information. If you have such data, you can open a Pull Request to add it to the package.If you have any questions pleaselet us know. You can learn more about our researchhere.Supported MetricsThere are many metrics which can possibly be used to detect Bias, we currently support the following three:Statistical Parity - tests whether the probability of 2 groups to be classified as belonging to the positive class by the model is equal.Equal Opportunity - tests whether the True Positive Rates of 2 groups are equal (how likely is the model to predict correctly the positive class for each group).Predictive Equality - tests whether there False Positive Rates of 2 groups are equal (how likely is the model to predict incorrectly the positive class for each group).UsageInstall the package!pip install bias-detectorCreate a bias detector instance:from bias_detector.BiasDetector import BiasDetector
bias_detector = BiasDetector(country='US')Generate bias report:bias_report = bias_detector.get_bias_report(first_names=first_names, last_names=last_names, zip_codes=zip_codes, y_true=y_true, y_pred=y_pred)Visualize the bias report:bias_report.plot_summary()bias_report.print_summary()Statistical Parity:We observed the following statistically significant differences (𝛼=0.01):P(pred=1|Male)-P(pred=1|Female)=0.55-0.49=0.053±0.026 (p-value=1e-07)Equal Opportunity:We observed the following statistically significant differences (𝛼=0.01):TPRMale-TPRFemale=0.56-0.51=0.047±0.036 (p-value=0.00097)Predictive Equality:We observed the following statistically significant differences (𝛼=0.01):FPRMale-FPRFemale=0.54-0.48=0.06±0.036 (p-value=2e-05)bias_report.plot_groups()Show gender/race correlation with model features:bias_detector.get_features_groups_correlation(first_names=first_names, last_names=last_names, zip_codes=zip_codes, features=features)Sample output from theTitanic demo:male_correlationfemale_correlationwhite_correlationblack_correlationapi_correlationhispanic_correlationnative_correlationticket_class-0.2437300.010038-0.122978-0.1522870.128161-0.003452-0.029846age0.234712-0.1686920.165937-0.059513-0.044503-0.0588930.036010num_of_siblings_or_spouses_aboard0.0276510.0257370.0292920.066896-0.061708-0.0720920.138135num_of_parents_or_children_aboard0.0575750.0427700.0486230.099354-0.064993-0.1004960.064185fare0.0537030.0713000.0763300.061158-0.001893-0.0676310.058121embarked_Cherbourg-0.073627-0.013599-0.093890-0.075407-0.0077200.124144-0.020478embarked_Queenstown-0.0192060.1697520.110737-0.049664-0.0493790.011407-0.054550embarked_Southampton0.082538-0.0906310.0111490.1002650.038108-0.1164380.050909sex_female-0.3270440.6152620.0473300.073640-0.0519590.0742590.011737sex_male0.327044-0.615262-0.047330-0.0736400.051959-0.074259-0.011737Fuzzy extraction of first/last names from emails:bias_detector.fuzzily_get_emails_full_names(emails)This method will return a DataFrame with first_name and last_name columns fuzzily extracted from the users emails. Note that the accuracy of this method varies between emails and data sets.Sample output for synthetic emails:emailfirst_namelast_nameholleybeverly@gmail.comholleybeverlybreweradrienne@gmail.comadriennebrewercraigreed@gmail.comcraigreedbattagliahenry@gmail.comhenrybattagliaapaget@gmail.compagetbriana@gmail.combrianaapena@gmail.compenajacka@gmail.comjackamattiea@gmail.commattiepatricia_calder@gmail.compatriciacalderContributingSeeCONTRIBUTING.md.ReferencesElhanan Mishraky, Aviv Ben Arie, Yair Horesh, Shir Meir Lador, 2021. Bias Detection by Using Name Disparity Tables Across Protected Groups, DOI: 10.1016/j.jrt.2021.100020Ninareh Mehrabi, Fred Morstatter, Nripsuta Saxena, Kristina Lerman, Aram Galstyan, 2019. A Survey on Bias and Fairness in Machine Learning.Moritz Hardt, Eric Price, Nathan Srebro, 2016. Equality of Opportunity in Supervised Learning.Ioan Voicu (2018) Using First Name Information to Improve Race and Ethnicity Classification, Statistics and Public Policy, 5:1, 1-13, DOI: 10.1080/2330443X.2018.1427012