Postprocess algorithms#

Post-process algorithms take predictions and transform them.

Postprocess base#

Abstract Base Class of all post-processing algorithms in the framework.

class PostAlgorithm#

Bases: Algorithm, ABC

Abstract Base Class for all algorithms that do post-processing.

abstract fit(train_predictions, train)#

Run Algorithm on the given data.

Parameters:
  • train_predictions (Prediction) – Predictions on a training set.

  • train (DataTuple) – The training set with the correct labels and sensitive attributes.

Returns:

Self.

Return type:

Self

abstract property name: str#

Name of the algorithm.

abstract predict(test_predictions, test, seed=888)#

Run Algorithm on the given data.

Parameters:
  • test_predictions (Prediction) – Predictions on a test set.

  • test (SubgroupTuple | DataTuple) – The test set with the sensitive attributes.

  • seed (int) – The random seed.

Returns:

Post-processed predictions on the test set.

Return type:

Prediction

abstract run(train_predictions, train, test_predictions, test, seed=888)#

Make predictions fair.

Parameters:
  • train_predictions (Prediction) – Predictions on a training set.

  • train (DataTuple) – The training set with the correct labels and sensitive attributes.

  • test_predictions (Prediction) – Predictions on the test set.

  • test (SubgroupTuple | DataTuple) – The test set with the sensitive attributes.

  • seed (int) – The random seed.

Returns:

Post-processed predictions on the test set.

Return type:

Prediction

DP Flip#

Demographic Parity Label flipping approach.

class DPFlip#

Bases: PostAlgorithm

Randomly flip a number of decisions such that perfect demographic parity is achieved.

fit(train_predictions, train)#

Run Algorithm on the given data.

Parameters:
  • train_predictions (Prediction) – Predictions on a training set.

  • train (DataTuple) – The training set with the correct labels and sensitive attributes.

Returns:

Self.

Return type:

Self

property name: str#

Name of the algorithm.

predict(test_predictions, test, seed=888)#

Run Algorithm on the given data.

Parameters:
  • test_predictions (Prediction) – Predictions on a test set.

  • test (SubgroupTuple | DataTuple) – The test set with the sensitive attributes.

  • seed (int) – The random seed.

Returns:

Post-processed predictions on the test set.

Return type:

Prediction

run(train_predictions, train, test_predictions, test, seed=888)#

Make predictions fair.

Parameters:
  • train_predictions (Prediction) – Predictions on a training set.

  • train (DataTuple) – The training set with the correct labels and sensitive attributes.

  • test_predictions (Prediction) – Predictions on the test set.

  • test (SubgroupTuple | DataTuple) – The test set with the sensitive attributes.

  • seed (int) – The random seed.

Returns:

Post-processed predictions on the test set.

Return type:

Prediction

Hardt#

Post-processing method by Hardt et al.

class Hardt(unfavorable_label=0, favorable_label=1)#

Bases: PostAlgorithm

Post-processing method by Hardt et al.

Parameters:
  • unfavorable_label (int) –

  • favorable_label (int) –

fit(train_predictions, train)#

Run Algorithm on the given data.

Parameters:
  • train_predictions (Prediction) – Predictions on a training set.

  • train (DataTuple) – The training set with the correct labels and sensitive attributes.

Returns:

Self.

Return type:

Self

property name: str#

Name of the algorithm.

predict(test_predictions, test, seed=888)#

Run Algorithm on the given data.

Parameters:
  • test_predictions (Prediction) – Predictions on a test set.

  • test (SubgroupTuple | DataTuple) – The test set with the sensitive attributes.

  • seed (int) – The random seed.

Returns:

Post-processed predictions on the test set.

Return type:

Prediction

run(train_predictions, train, test_predictions, test, seed=888)#

Make predictions fair.

Parameters:
  • train_predictions (Prediction) – Predictions on a training set.

  • train (DataTuple) – The training set with the correct labels and sensitive attributes.

  • test_predictions (Prediction) – Predictions on the test set.

  • test (SubgroupTuple | DataTuple) – The test set with the sensitive attributes.

  • seed (int) – The random seed.

Returns:

Post-processed predictions on the test set.

Return type:

Prediction