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¶
datasets.NumericConversionWarning |
Warning used if protected attribute or target is unable to be converted automatically to a numeric type. |
datasets.standardize_dataset (df, *, …[, …]) |
Separate data, targets, and possibly sample weights and populate protected attributes as sample properties. |
Loaders¶
datasets.fetch_adult ([subset, data_home, …]) |
Load the Adult Census Income Dataset. |
datasets.fetch_german (*[, data_home, cache, …]) |
Load the German Credit Dataset. |
datasets.fetch_bank (*[, data_home, cache, …]) |
Load the Bank Marketing Dataset. |
datasets.fetch_compas ([subset, data_home, …]) |
Load the COMPAS Recidivism Risk Scores dataset. |
datasets.fetch_lawschool_gpa ([subset, …]) |
Load the Law School GPA dataset |
datasets.fetch_meps (panel, *[, …]) |
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¶
metrics.difference (func, y_true[, y_pred, …]) |
Compute the difference between unprivileged and privileged subsets for an arbitrary metric. |
metrics.ratio (func, y_true[, y_pred, …]) |
Compute the ratio between unprivileged and privileged subsets for an arbitrary metric. |
metrics.intersection (func, y_true[, y_pred, …]) |
Compute an arbitrary metric on all intersectional groups of the protected attributes provided. |
metrics.one_vs_rest (func, y_true[, y_pred, …]) |
Compute an arbitrary difference/ratio metric on all intersectional groups of the protected attributes provided in a one-vs-rest manner. |
Scorers¶
metrics.make_scorer (score_func[, is_ratio]) |
Make a scorer from a ‘difference’ or ‘ratio’ metric (e.g. |
Generic metrics¶
metrics.num_samples (y_true[, y_pred, …]) |
Compute the number of samples. |
metrics.num_pos_neg (y_true[, y_pred, …]) |
Compute the number of positive and negative samples. |
metrics.specificity_score (y_true, y_pred, *) |
Compute the specificity or true negative rate. |
metrics.sensitivity_score (y_true, y_pred[, …]) |
Alias of sklearn.metrics.recall_score() for binary classes only. |
metrics.base_rate (y_true[, y_pred, …]) |
Compute the base rate, \(Pr(Y = \text{pos_label}) = \frac{P}{P+N}\). |
metrics.selection_rate (y_true, y_pred, *[, …]) |
Compute the selection rate, \(Pr(\hat{Y} = \text{pos_label}) = \frac{TP + FP}{P + N}\). |
metrics.smoothed_base_rate (y_true[, y_pred, …]) |
Compute the smoothed base rate, \(\frac{P + \alpha}{P + N + |R_Y|\alpha}\). |
metrics.smoothed_selection_rate (y_true, …) |
Compute the smoothed selection rate, \(\frac{TP + FP + \alpha}{P + N + |R_Y|\alpha}\). |
metrics.generalized_fpr (y_true, probas_pred, *) |
Return the ratio of generalized false positives to negative examples in the dataset, \(GFPR = \tfrac{GFP}{N}\). |
metrics.generalized_fnr (y_true, probas_pred, *) |
Return the ratio of generalized false negatives to positive examples in the dataset, \(GFNR = \tfrac{GFN}{P}\). |
Group fairness metrics¶
metrics.statistical_parity_difference (y_true) |
Difference in selection rates. |
metrics.mean_difference (y_true[, y_pred, …]) |
Alias of statistical_parity_difference() . |
metrics.disparate_impact_ratio (y_true[, …]) |
Ratio of selection rates. |
metrics.equal_opportunity_difference (y_true, …) |
A relaxed version of equality of opportunity. |
metrics.average_odds_difference (y_true, …) |
A relaxed version of equality of odds. |
metrics.average_odds_error (y_true, y_pred, *) |
A relaxed version of equality of odds. |
metrics.class_imbalance (y_true[, y_pred, …]) |
Compute the class imbalance, \(\frac{N_u - N_p}{N_u + N_p}\). |
metrics.kl_divergence (y_true[, y_pred, …]) |
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)\) |
metrics.conditional_demographic_disparity (y_true) |
Conditional demographic disparity, \(CDD = \frac{1}{\sum_i N_i} \sum_i N_i\cdot DD_i\) |
metrics.smoothed_edf (y_true[, y_pred, …]) |
Smoothed empirical differential fairness (EDF). |
metrics.df_bias_amplification (y_true, y_pred, *) |
Differential fairness bias amplification. |
metrics.between_group_generalized_entropy_error (…) |
Compute the between-group generalized entropy. |
metrics.mdss_bias_scan (y_true, probas_pred) |
DEPRECATED: Change to new interface - aif360.sklearn.detectors.mdss_detector.bias_scan by version 0.5.0. |
metrics.mdss_bias_score (y_true, probas_pred) |
Compute the bias score for a prespecified group of records using a given scoring function. |
Individual fairness metrics¶
metrics.generalized_entropy_index (b[, alpha]) |
Generalized entropy index measures inequality over a population. |
metrics.generalized_entropy_error (y_true, y_pred) |
Compute the generalized entropy. |
metrics.theil_index (b) |
The Theil index is the generalized_entropy_index() with \(\alpha = 1\). |
metrics.coefficient_of_variation (b) |
The coefficient of variation is the square root of two times the generalized_entropy_index() with \(\alpha = 2\). |
metrics.consistency_score (X, y[, n_neighbors]) |
Compute the consistency score. |
aif360.sklearn.detectors
: Bias detection methods¶
Methods for detecting subsets for which a model or dataset is biased.
Bias scan¶
detectors.bias_scan (X, y_true, y_pred, …) |
Scan to find the highest scoring subset of records. |
aif360.sklearn.preprocessing
: Pre-processing algorithms¶
Pre-processing algorithms modify a dataset to be more fair (data in, data out).
Pre-processors¶
preprocessing.FairAdapt (prot_attr, adj_mat) |
Fair Data Adaptation. |
preprocessing.LearnedFairRepresentations ([…]) |
Learned Fair Representations. |
preprocessing.Reweighing ([prot_attr]) |
Sample reweighing. |
Meta-Estimator¶
preprocessing.ReweighingMeta (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¶
inprocessing.AdversarialDebiasing ([…]) |
Debiasing with adversarial learning. |
inprocessing.ExponentiatedGradientReduction (…) |
Exponentiated gradient reduction for fair classification. |
inprocessing.GridSearchReduction (prot_attr, …) |
Grid search reduction for fair classification or regression. |
aif360.sklearn.postprocessing
: Post-processing algorithms¶
Post-processing algorithms modify predictions to be more fair (predictions in, predictions out).
Post-processors¶
postprocessing.CalibratedEqualizedOdds ([…]) |
Calibrated equalized odds post-processor. |
postprocessing.RejectOptionClassifier ([…]) |
Reject option based classification (ROC) post-processor. |
Meta-Estimator¶
postprocessing.PostProcessingMeta (estimator, …) |
A meta-estimator which wraps a given estimator with a post-processing step. |
aif360.sklearn.utils
: Utility functions¶
Validation¶
utils.check_inputs (X, y[, sample_weight, …]) |
Input validation for debiasing algorithms. |
utils.check_groups (arr, prot_attr[, …]) |
Get groups from the index of arr. |