A Python package to check for algorithmic bias.
Project description
This package provides functions to test one's ML models bias.
BiasBuster package
The metrics are calculated by a slicing analysis. Four fairness metrics are supported: ABROCA, Equal Opportunity, Predictive Equality and Predictive Parity.
ABROCA: met, if both groups have equal Absolute Between ROC Area Equal Opportunity: met, if both groups have equal FNR Predictive Equality: met, if both groups have equal FPR Predictive Parity: met, if both groups have the same PPV
Installation
This package can be installed using pip. An installation with pip automatically downloads the latest version from PyPI:
pip install BiasBuster
Example & Usage
Import the metric you'd like to use.
from BiasBuster import abroca
from BiasBuster import predictive_equality
from BiasBuster import predictive_parity
from BiasBuster import equal_opportunity
df = load_your_dataset
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)
clf = DecisionTreeClassifier(criterion="entropy", splitter="best")
clf = clf.fit(X_train, y_train)
X_test_advantaged = X_test[X_test['group'] == 1]
y_test_advantaged = y_test[y_test['group'] == 1]
X_test_disadv = X_test[X_test['group'] == 0]
y_test_disadv =y_test[y_test['group'] == 0]
abroca = abroca.calculate_abroca(clf,X_test_advantaged,y_test_advantaged, X_test_disadv, y_test_disadv)
pe = predictive_equality.predictive_equality(clf,X_test_advantaged,y_test_advantaged, X_test_disadv, y_test_disadv)
pp = predictive_parity.calculate_predictive_parity(clf,X_test_advantaged,y_test_advantaged, X_test_disadv, y_test_disadv)
eo =equal_opportunity.calculate_equal_opportunity(clf,X_test_advantaged,y_test_advantaged, X_test_disadv, y_test_disadv)
print(abroca)
-0.005211848509902417
Interpretation
The threshold to delineate biased from unbiased depends on the underlying data. However, typical thresholds lie between 0.01 and 0.05.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file BiasBuster-0.0.4.tar.gz.
File metadata
- Download URL: BiasBuster-0.0.4.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc24a1ba8cea90df4e6ddc9e98193968280ca33ec077ca4240b2ebde84cf0ce0
|
|
| MD5 |
d40768e53ed6305f8e1f7f5c494ba99e
|
|
| BLAKE2b-256 |
6cb9de63cbe18d3b13bd71aefa0410bf92d685335fe09b8349f76b71fdf52537
|
File details
Details for the file BiasBuster-0.0.4-py3-none-any.whl.
File metadata
- Download URL: BiasBuster-0.0.4-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af1a123d9b3573dc088692ae854dbc75b4eed165f98540f08413140cbc435af0
|
|
| MD5 |
91e750fd8988dd1b8bb9b29be6436542
|
|
| BLAKE2b-256 |
02ba952d5d8eab720c2bfb90f1629d0bd8d0f04b606bdf0787d7faec4ffbdcd4
|