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
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
Returns

predictions

Return type

ethicml.utility.data_structures.Prediction

run(train_predictions, train, test_predictions, test)#

Make predictions fair.

Parameters
Returns

post-processed predictions on the test set

Return type

ethicml.utility.data_structures.Prediction

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
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
Returns

predictions

Return type

ethicml.utility.data_structures.Prediction

run(train_predictions, train, test_predictions, test)#

Make predictions fair.

Parameters
Returns

post-processed predictions on the test set

Return type

ethicml.utility.data_structures.Prediction

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
Returns

self, but trained.

Return type

ethicml.algorithms.postprocess.dp_flip.DPFlip

property name: str#

Name of the algorithm.

predict(test_predictions, test)#

Run Algorithm on the given data.

Parameters
Returns

predictions

Return type

ethicml.utility.data_structures.Prediction

run(train_predictions, train, test_predictions, test)#

Make predictions fair.

Parameters
Returns

post-processed predictions on the test set

Return type

ethicml.utility.data_structures.Prediction

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
Returns

self, but trained.

Return type

ethicml.algorithms.postprocess.post_algorithm.PostAlgorithm

property name: str#

Name of the algorithm.

predict(test_predictions, test)#

Run Algorithm on the given data.

Parameters
Returns

predictions

Return type

ethicml.utility.data_structures.Prediction

run(train_predictions, train, test_predictions, test)#

Make predictions fair.

Parameters
Returns

post-processed predictions on the test set

Return type

ethicml.utility.data_structures.Prediction