aif360.algorithms.inprocessing

Adversarial Debiasing

class aif360.algorithms.inprocessing.AdversarialDebiasing(unprivileged_groups, privileged_groups, scope_name, sess, seed=None, adversary_loss_weight=0.1, num_epochs=50, batch_size=128, classifier_num_hidden_units=200, debias=True)[source]

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]. This approach leads to a fair classifier as the predictions cannot carry any group discrimination information that the adversary can exploit.

References

[5]B. H. Zhang, B. Lemoine, and M. Mitchell, “Mitigating Unwanted Biases with Adversarial Learning,” AAAI/ACM Conference on Artificial Intelligence, Ethics, and Society, 2018.
Parameters:
  • unprivileged_groups (tuple) – Representation for unprivileged groups
  • privileged_groups (tuple) – Representation for privileged groups
  • scope_name (str) – scope name for the tenforflow variables
  • sess (tf.Session) – tensorflow session
  • seed (int, optional) – Seed to make predict repeatable.
  • adversary_loss_weight (float, optional) – Hyperparameter that chooses the strength of the adversarial loss.
  • num_epochs (int, optional) – Number of training epochs.
  • batch_size (int, optional) – Batch size.
  • classifier_num_hidden_units (int, optional) – Number of hidden units in the classifier model.
  • debias (bool, optional) – Learn a classifier with or without debiasing.
fit(dataset)[source]

Compute the model parameters of the fair classifier using gradient descent.

Parameters:dataset (BinaryLabelDataset) – Dataset containing true labels.
Returns:Returns self.
Return type:AdversarialDebiasing
fit_predict(dataset)

Train a model on the input and predict the labels.

Equivalent to calling fit(dataset) followed by predict(dataset).

Parameters:dataset (Dataset) – Input dataset.
Returns:Output dataset. metadata should reflect the details of this transformation.
Return type:Dataset
predict(dataset)[source]

Obtain the predictions for the provided dataset using the fair classifier learned.

Parameters:dataset (BinaryLabelDataset) – Dataset containing labels that needs to be transformed.
Returns:Transformed dataset.
Return type:dataset (BinaryLabelDataset)

ART Classifier

class aif360.algorithms.inprocessing.ARTClassifier(art_classifier)[source]

Wraps an instance of an art.classifiers.Classifier to extend Transformer.

Initialize ARTClassifier.

Parameters:art_classifier (art.classifier.Classifier) – A Classifier object from the adversarial-robustness-toolbox.
fit(dataset, batch_size=128, nb_epochs=20)[source]

Train a classifer on the input.

Parameters:
  • dataset (Dataset) – Training dataset.
  • batch_size (int) – Size of batches (passed through to ART).
  • nb_epochs (int) – Number of epochs to use for training (passed through to ART).
Returns:

Returns self.

Return type:

ARTClassifier

fit_predict(dataset)

Train a model on the input and predict the labels.

Equivalent to calling fit(dataset) followed by predict(dataset).

Parameters:dataset (Dataset) – Input dataset.
Returns:Output dataset. metadata should reflect the details of this transformation.
Return type:Dataset
predict(dataset, logits=False)[source]

Perform prediction for the input.

Parameters:
  • dataset (Dataset) – Test dataset.
  • logits (bool, optional) – True is prediction should be done at the logits layer (passed through to ART).
Returns:

Dataset with predicted labels in the labels field.

Return type:

Dataset

Meta Fair Classifier

class aif360.algorithms.inprocessing.MetaFairClassifier(tau=0.8, sensitive_attr='', type='fdr')[source]

The meta algorithm here takes the fairness metric as part of the input and returns a classifier optimized w.r.t. that fairness metric [11].

References

[11]L. E. Celis, L. Huang, V. Keswani, and N. K. Vishnoi. “Classification with Fairness Constraints: A Meta-Algorithm with Provable Guarantees,” 2018.
Parameters:
  • tau (double, optional) – Fairness penalty parameter.
  • sensitive_attr (str, optional) – Name of protected attribute.
  • type (str, optional) – The type of fairness metric to be used. Currently “fdr” (false discovery rate ratio) and “sr” (statistical rate/disparate impact) are supported. To use another type, the corresponding optimization class has to be implemented.
fit(dataset)[source]

Learns the fair classifier.

Parameters:dataset (BinaryLabelDataset) – Dataset containing true labels.
Returns:Returns self.
Return type:MetaFairClassifier
fit_predict(dataset)

Train a model on the input and predict the labels.

Equivalent to calling fit(dataset) followed by predict(dataset).

Parameters:dataset (Dataset) – Input dataset.
Returns:Output dataset. metadata should reflect the details of this transformation.
Return type:Dataset
predict(dataset)[source]

Obtain the predictions for the provided dataset using the learned classifier model.

Parameters:dataset (BinaryLabelDataset) – Dataset containing labels that needs to be transformed.
Returns:Transformed dataset.
Return type:BinaryLabelDataset

Prejudice Remover

class aif360.algorithms.inprocessing.PrejudiceRemover(eta=1.0, sensitive_attr='', class_attr='')[source]

Prejudice remover is an in-processing technique that adds a discrimination-aware regularization term to the learning objective [6].

References

[6]T. Kamishima, S. Akaho, H. Asoh, and J. Sakuma, “Fairness-Aware Classifier with Prejudice Remover Regularizer,” Joint European Conference on Machine Learning and Knowledge Discovery in Databases, 2012.
Parameters:
  • eta (double, optional) – fairness penalty parameter
  • sensitive_attr (str, optional) – name of protected attribute
  • class_attr (str, optional) – label name
fit(dataset)[source]

Learns the regularized logistic regression model.

Parameters:dataset (BinaryLabelDataset) – Dataset containing true labels.
Returns:Returns self.
Return type:PrejudiceRemover
fit_predict(dataset)

Train a model on the input and predict the labels.

Equivalent to calling fit(dataset) followed by predict(dataset).

Parameters:dataset (Dataset) – Input dataset.
Returns:Output dataset. metadata should reflect the details of this transformation.
Return type:Dataset
predict(dataset)[source]

Obtain the predictions for the provided dataset using the learned prejudice remover model.

Parameters:dataset (BinaryLabelDataset) – Dataset containing labels that needs to be transformed.
Returns:Transformed dataset.
Return type:dataset (BinaryLabelDataset)