scikit-learn
-Compatible API Reference
This is the class and function reference for the scikit-learn
-compatible
version of the AIF360 API. It is functionally equivalent to the normal API but
it uses scikit-learn paradigms (where possible) and pandas.DataFrame
for
datasets. Not all functionality from AIF360 is supported yet. See
Getting Started
for a demo of the capabilities.
Note: This is under active development. Visit our GitHub page if you’d like to contribute!
aif360.sklearn.datasets
: Dataset loading functions
The dataset format for aif360.sklearn
is a pandas.DataFrame
with
protected attributes in the index.
Warning
Currently, while all scikit-learn classes will accept DataFrames as inputs,
most classes will return a numpy.ndarray
. Therefore, many pre-
processing steps, when placed before an aif360.sklearn
step in a
Pipeline, will cause errors.
Utils
Warning used if protected attribute or target is unable to be converted automatically to a numeric type. |
|
Separate data, targets, and possibly sample weights and populate protected attributes as sample properties. |
Loaders
|
Load the Adult Census Income Dataset. |
|
Load the German Credit Dataset. |
|
Load the Bank Marketing Dataset. |
|
Load the COMPAS Recidivism Risk Scores dataset. |
|
Load the Law School GPA dataset. |
|
Load the Medical Expenditure Panel Survey (MEPS) dataset. |
aif360.sklearn.metrics
: Fairness metrics
aif360.sklearn
implements a number of fairness metrics for group fairness
and individual fairness. For guidance on which metric to use for a given
application, see our
Guidance page.
Meta-metrics
|
Compute the difference between unprivileged and privileged subsets for an arbitrary metric. |
|
Compute the ratio between unprivileged and privileged subsets for an arbitrary metric. |
|
Compute an arbitrary metric on all intersectional groups of the protected attributes provided. |
|
Compute an arbitrary difference/ratio metric on all intersectional groups of the protected attributes provided in a one-vs-rest manner. |
Scorers
|
Make a scorer from a 'difference' or 'ratio' metric (e.g. |
Generic metrics
|
Compute the number of samples. |
|
Compute the number of positive and negative samples. |
|
Compute the specificity or true negative rate. |
|
Alias of |
|
Compute the base rate, \(Pr(Y = \text{pos_label}) = \frac{P}{P+N}\). |
|
Compute the selection rate, \(Pr(\hat{Y} = \text{pos_label}) = \frac{TP + FP}{P + N}\). |
|
Compute the smoothed base rate, \(\frac{P + \alpha}{P + N + |R_Y|\alpha}\). |
|
Compute the smoothed selection rate, \(\frac{TP + FP + \alpha}{P + N + |R_Y|\alpha}\). |
|
Return the ratio of generalized false positives to negative examples in the dataset, \(GFPR = \tfrac{GFP}{N}\). |
|
Return the ratio of generalized false negatives to positive examples in the dataset, \(GFNR = \tfrac{GFN}{P}\). |
Group fairness metrics
Difference in selection rates. |
|
|
Alias of |
|
Ratio of selection rates. |
|
A relaxed version of equality of opportunity. |
|
A relaxed version of equality of odds. |
|
A relaxed version of equality of odds. |
|
Compute the class imbalance, \(\frac{N_u - N_p}{N_u + N_p}\). |
|
Compute the Kullback-Leibler divergence, \(KL(P_p||P_u) = \sum_y P_p(y)\log\left(\frac{P_p(y)}{P_u(y)}\right)\) |
Conditional demographic disparity, \(CDD = \frac{1}{\sum_i N_i} \sum_i N_i\cdot DD_i\) |
|
|
Smoothed empirical differential fairness (EDF). |
|
Differential fairness bias amplification. |
Compute the between-group generalized entropy. |
|
|
Compute the bias score for a prespecified group of records using a given scoring function. |
Individual fairness metrics
|
Generalized entropy index measures inequality over a population. |
|
Compute the generalized entropy. |
The Theil index is the |
|
The coefficient of variation is the square root of two times the |
|
|
Compute the consistency score. |
aif360.sklearn.detectors
: Bias detection methods
Methods for detecting subsets for which a model or dataset is biased.
Bias scan
|
Scan to find the highest scoring subset of records. |
|
Identify the subgroups with the most difficulty achieving recourse. |
|
Fairness aware counterfactuals for subgroups (FACTS) detector. |
aif360.sklearn.preprocessing
: Pre-processing algorithms
Pre-processing algorithms modify a dataset to be more fair (data in, data out).
Pre-processors
|
Fair Data Adaptation. |
Learned Fair Representations. |
|
|
Sample reweighing. |
Meta-Estimator
|
A meta-estimator which wraps a given estimator with a reweighing preprocessing step. |
aif360.sklearn.inprocessing
: In-processing algorithms
In-processing algorithms train a fair classifier (data in, predictions out).
In-processors
Debiasing with adversarial learning. |
|
Exponentiated gradient reduction for fair classification. |
|
|
Grid search reduction for fair classification or regression. |
|
Sensitive Set Invariance (SenSeI). |
|
Sensitive Subspace Robustness (SenSR). |
aif360.sklearn.postprocessing
: Post-processing algorithms
Post-processing algorithms modify predictions to be more fair (predictions in, predictions out).
Post-processors
Calibrated equalized odds post-processor. |
|
Reject option based classification (ROC) post-processor. |
Meta-Estimator
|
A meta-estimator which wraps a given estimator with a post-processing step. |
aif360.sklearn.utils
: Utility functions
Validation
|
Input validation for debiasing algorithms. |
|
Get groups from the index of arr. |