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(*args, **kwargs)#
Bases:
ethicml.algorithms.algorithm_base.Algorithm
,Protocol
Abstract Base Class for all algorithms that do post-processing.
- abstract fit(train_predictions, train)#
Run Algorithm on the given data.
- Parameters
train (ethicml.utility.data_structures.DataTuple) – training data
self (ethicml.algorithms.postprocess.post_algorithm._PA) –
train_predictions (ethicml.utility.data_structures.Prediction) –
- Returns
self, but trained.
- Return type
ethicml.algorithms.postprocess.post_algorithm._PA
- abstract property name: str#
Name of the algorithm.
- abstract predict(test_predictions, test)#
Run Algorithm on the given data.
- Parameters
test (ethicml.utility.data_structures.TestTuple) – data to evaluate on
test_predictions (ethicml.utility.data_structures.Prediction) –
- Returns
predictions
- Return type
- run(train_predictions, train, test_predictions, test)#
Make predictions fair.
- Parameters
train_predictions (ethicml.utility.data_structures.Prediction) – predictions on a training set
train (ethicml.utility.data_structures.DataTuple) – the training set with the correct labels and sensitive attributes
test_predictions (ethicml.utility.data_structures.Prediction) – predictions on the test set
test (ethicml.utility.data_structures.TestTuple) – the test set with the sensitive attributes
- Returns
post-processed predictions on the test set
- Return type
- class PostAlgorithmDC(seed=888)#
Bases:
ethicml.algorithms.postprocess.post_algorithm.PostAlgorithm
PostAlgorithm dataclass base class.
- Parameters
seed (int) –
- Return type
None
- abstract fit(train_predictions, train)#
Run Algorithm on the given data.
- Parameters
train (ethicml.utility.data_structures.DataTuple) – training data
self (ethicml.algorithms.postprocess.post_algorithm._PA) –
train_predictions (ethicml.utility.data_structures.Prediction) –
- Returns
self, but trained.
- Return type
ethicml.algorithms.postprocess.post_algorithm._PA
- abstract property name: str#
Name of the algorithm.
- abstract predict(test_predictions, test)#
Run Algorithm on the given data.
- Parameters
test (ethicml.utility.data_structures.TestTuple) – data to evaluate on
test_predictions (ethicml.utility.data_structures.Prediction) –
- Returns
predictions
- Return type
- run(train_predictions, train, test_predictions, test)#
Make predictions fair.
- Parameters
train_predictions (ethicml.utility.data_structures.Prediction) – predictions on a training set
train (ethicml.utility.data_structures.DataTuple) – the training set with the correct labels and sensitive attributes
test_predictions (ethicml.utility.data_structures.Prediction) – predictions on the test set
test (ethicml.utility.data_structures.TestTuple) – the test set with the sensitive attributes
- Returns
post-processed predictions on the test set
- Return type
DP Flip#
Demographic Parity Label flipping approach.
- class DPFlip(seed=888)#
Bases:
ethicml.algorithms.postprocess.post_algorithm.PostAlgorithmDC
Randomly flip a number of decisions such that perfect demographic parity is achieved.
- Parameters
seed (int) –
- Return type
None
- fit(train_predictions, train)#
Run Algorithm on the given data.
- Parameters
train (ethicml.utility.data_structures.DataTuple) – training data
train_predictions (ethicml.utility.data_structures.Prediction) –
- Returns
self, but trained.
- Return type
- property name: str#
Name of the algorithm.
- predict(test_predictions, test)#
Run Algorithm on the given data.
- Parameters
test (ethicml.utility.data_structures.TestTuple) – data to evaluate on
test_predictions (ethicml.utility.data_structures.Prediction) –
- Returns
predictions
- Return type
- run(train_predictions, train, test_predictions, test)#
Make predictions fair.
- Parameters
train_predictions (ethicml.utility.data_structures.Prediction) – predictions on a training set
train (ethicml.utility.data_structures.DataTuple) – the training set with the correct labels and sensitive attributes
test_predictions (ethicml.utility.data_structures.Prediction) – predictions on the test set
test (ethicml.utility.data_structures.TestTuple) – the test set with the sensitive attributes
- Returns
post-processed predictions on the test set
- Return type
Hardt#
Post-processing method by Hardt et al.
- class Hardt(*, unfavorable_label=0, favorable_label=1, seed=888)#
Bases:
ethicml.algorithms.postprocess.post_algorithm.PostAlgorithm
Post-processing method by Hardt et al.
- Parameters
unfavorable_label (int) –
favorable_label (int) –
seed (int) –
- fit(train_predictions, train)#
Run Algorithm on the given data.
- Parameters
train (ethicml.utility.data_structures.DataTuple) – training data
train_predictions (ethicml.utility.data_structures.Prediction) –
- Returns
self, but trained.
- Return type
- property name: str#
Name of the algorithm.
- predict(test_predictions, test)#
Run Algorithm on the given data.
- Parameters
test (ethicml.utility.data_structures.TestTuple) – data to evaluate on
test_predictions (ethicml.utility.data_structures.Prediction) –
- Returns
predictions
- Return type
- run(train_predictions, train, test_predictions, test)#
Make predictions fair.
- Parameters
train_predictions (ethicml.utility.data_structures.Prediction) – predictions on a training set
train (ethicml.utility.data_structures.DataTuple) – the training set with the correct labels and sensitive attributes
test_predictions (ethicml.utility.data_structures.Prediction) – predictions on the test set
test (ethicml.utility.data_structures.TestTuple) – the test set with the sensitive attributes
- Returns
post-processed predictions on the test set
- Return type