AI Fairness 360 documentation

Algorithms

aif360.algorithms.preprocessing

algorithms.preprocessing.DisparateImpactRemover([…]) Disparate impact remover is a preprocessing technique that edits feature values increase group fairness while preserving rank-ordering within groups [1]_.
algorithms.preprocessing.LFR(…[, k, Ax, …]) Learning fair representations is a pre-processing technique that finds a latent representation which encodes the data well but obfuscates information about protected attributes [2]_.
algorithms.preprocessing.OptimPreproc(…[, …]) Optimized preprocessing is a preprocessing technique that learns a probabilistic transformation that edits the features and labels in the data with group fairness, individual distortion, and data fidelity constraints and objectives [3]_.
algorithms.preprocessing.Reweighing(…) Reweighing is a preprocessing technique that Weights the examples in each (group, label) combination differently to ensure fairness before classification [4]_.

aif360.algorithms.inprocessing

algorithms.inprocessing.AdversarialDebiasing(…) Adversarial debiasing is an in-processing technique that learns a classifier to maximize prediction accuracy and simultaneously reduce an adversary’s ability to determine the protected attribute from the predictions [5]_.
algorithms.inprocessing.ARTClassifier(…) Wraps an instance of an art.classifiers.Classifier to extend Transformer.
algorithms.inprocessing.GerryFairClassifier([…]) Model is an algorithm for learning classifiers that are fair with respect to rich subgroups.
algorithms.inprocessing.MetaFairClassifier([…]) The meta algorithm here takes the fairness metric as part of the input and returns a classifier optimized w.r.t.
algorithms.inprocessing.PrejudiceRemover([…]) Prejudice remover is an in-processing technique that adds a discrimination-aware regularization term to the learning objective [6]_.
algorithms.inprocessing.ExponentiatedGradientReduction(…) Exponentiated gradient reduction for fair classification.
algorithms.inprocessing.GridSearchReduction(…) Grid search reduction for fair classification or regression.

aif360.algorithms.postprocessing

algorithms.postprocessing.CalibratedEqOddsPostprocessing(…) Calibrated equalized odds postprocessing is a post-processing technique that optimizes over calibrated classifier score outputs to find probabilities with which to change output labels with an equalized odds objective [7]_.
algorithms.postprocessing.EqOddsPostprocessing(…) Equalized odds postprocessing is a post-processing technique that solves a linear program to find probabilities with which to change output labels to optimize equalized odds [8]_ [9]_.
algorithms.postprocessing.RejectOptionClassification(…) Reject option classification is a postprocessing technique that gives favorable outcomes to unpriviliged groups and unfavorable outcomes to priviliged groups in a confidence band around the decision boundary with the highest uncertainty [10]_.

aif360.algorithms

algorithms.Transformer(**kwargs) Abstract base class for transformers.

Datasets

aif360.datasets

Base classes

datasets.Dataset(**kwargs) Abstract base class for datasets.
datasets.StructuredDataset(df, label_names, …) Base class for all structured datasets.
datasets.BinaryLabelDataset([…]) Base class for all structured datasets with binary labels.
datasets.StandardDataset(df, label_name, …) Base class for every BinaryLabelDataset provided out of the box by aif360.
datasets.RegressionDataset(df, dep_var_name, …) Base class for regression datasets.

Common datasets

datasets.AdultDataset([label_name, …]) Adult Census Income Dataset.
datasets.BankDataset([label_name, …]) Bank marketing Dataset.
datasets.CompasDataset([label_name, …]) ProPublica COMPAS Dataset.
datasets.GermanDataset([label_name, …]) German credit Dataset.
datasets.LawSchoolGPADataset([dep_var_name, …]) Law School GPA dataset.
datasets.MEPSDataset19([label_name, …]) MEPS Dataset.
datasets.MEPSDataset20([label_name, …]) MEPS Dataset.
datasets.MEPSDataset21([label_name, …]) MEPS Dataset.

Explainers

aif360.explainers

explainers.MetricTextExplainer(metric) Class for explaining metric values with text.
explainers.MetricJSONExplainer(metric) Class for explaining metric values in JSON format.

Fairness Metrics

aif360.metrics

metrics.DatasetMetric(dataset[, …]) Class for computing metrics based on one StructuredDataset.
metrics.BinaryLabelDatasetMetric(dataset[, …]) Class for computing metrics based on a single BinaryLabelDataset.
metrics.ClassificationMetric(dataset, …[, …]) Class for computing metrics based on two BinaryLabelDatasets.
metrics.SampleDistortionMetric(dataset, …) Class for computing metrics based on two StructuredDatasets.
metrics.MDSSClassificationMetric(dataset, …) Bias subset scanning is proposed as a technique to identify bias in predictive models using subset scanning [#zhang16]_.

aif360.metrics.utils

This is the helper script for implementing metrics.

metrics.utils.compute_boolean_conditioning_vector(X, …) Compute the boolean conditioning vector.
metrics.utils.compute_num_instances(X, w, …) Compute the number of instances, \(n\), conditioned on the protected attribute(s).
metrics.utils.compute_num_pos_neg(X, y, w, …) Compute the number of positives, \(P\), or negatives, \(N\), optionally conditioned on protected attributes.
metrics.utils.compute_num_TF_PN(X, y_true, …) Compute the number of true/false positives/negatives optionally conditioned on protected attributes.
metrics.utils.compute_num_gen_TF_PN(X, …) Compute the number of generalized true/false positives/negatives optionally conditioned on protected attributes.
metrics.utils.compute_distance(X_orig, …) Compute the distance element-wise for two sets of vectors.

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.

Indices and tables