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.ColumnAlreadyDroppedWarning Warning used if a column is attempted to be dropped twice.
datasets.check_already_dropped(labels, …) Check if columns have already been dropped and return only those that haven’t.
datasets.standardize_dataset(df, prot_attr, …) Separate data, targets, and possibly sample weights and populate protected attributes as sample properties.
datasets.to_dataframe(data) Format an OpenML dataset Bunch as a DataFrame with categorical features if needed.

Loaders

datasets.fetch_adult([subset, data_home, …]) Load the Adult Census Income Dataset.
datasets.fetch_german([data_home, …]) Load the German Credit Dataset.
datasets.fetch_bank([data_home, percent10, …]) Load the Bank Marketing Dataset.
datasets.fetch_compas([data_home, …]) Load the COMPAS Recidivism Risk Scores dataset.
datasets.fetch_lawschool_gpa([subset, …]) Load the Law School GPA 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, *args[, …]) Compute the difference between unprivileged and privileged subsets for an arbitrary metric.
metrics.ratio(func, y, *args[, prot_attr, …]) Compute the ratio between unprivileged and privileged subsets for an arbitrary metric.

Scorers

metrics.make_scorer(score_func[, is_ratio]) Make a scorer from a ‘difference’ or ‘ratio’ metric (e.g.

Generic metrics

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.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[, …]) Difference in selection rates.
metrics.mean_difference(*y[, prot_attr, …]) Alias of statistical_parity_difference().
metrics.disparate_impact_ratio(*y[, …]) Ratio of selection rates.
metrics.equal_opportunity_difference(y_true, …) A relaxed version of equality of opportunity.
metrics.average_odds_difference(y_true, y_pred) A relaxed version of equality of odds.
metrics.average_odds_error(y_true, y_pred[, …]) A relaxed version of equality of odds.
metrics.between_group_generalized_entropy_error(…) Compute the between-group generalized entropy.

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 two times the square root of the generalized_entropy_index() with \(\alpha = 2\).
metrics.consistency_score(X, y[, n_neighbors]) Compute the consistency score.

aif360.sklearn.preprocessing: Pre-processing algorithms

Pre-processors

preprocessing.Reweighing
preprocessing.FairAdapt

Meta-Estimator

preprocessing.ReweighingMeta

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.

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.