holisticai.bias.mitigation.FairletClustering#

class holisticai.bias.mitigation.FairletClustering(*args, **kargs)[source]#

Fairlet Clustering [1] inprocessing bias mitigation works in two steps:

  1. The pointset is partitioned into subsets called fairlets that satisfy the fairness requirement and approximately preserve the k-median objective.

  2. Fairlets are merged into k clusters by one of the existing k-median algorithms.

Parameters

n_clustersint

The number of clusters to form as well as the number of centroids to generate.

decompositionstr

Fairlet decomposition strategy, available: Vanilla, Scalable

clustering_modelstr

specified lambda parameter

pint

fairlet decomposition parameter for Vanilla and Scalable strategy

qint

fairlet decomposition parameter for Vanilla and Scalable strategy

seedint

Random seed.

Examples

>>> from holisticai.bias.mitigation import FairletClustering
>>> mitigator = FairletClustering(**params)
>>> mitigator.fit(train_data, group_a, group_b)
>>> train_data_transformed = mitigator.predict(train_data)

References

fit(X: ndarray, group_a: ndarray, group_b: ndarray)[source]#

Fit the model

Description

Learn a fair cluster.

Parameters

Xnumpy array

input matrix

group_anumpy array

binary mask vector

group_bnumpy array

binary mask vector

Returns

self

fit_predict(X: ndarray, group_a: ndarray, group_b: ndarray)[source]#

Prediction

Description

Fit and Predict the cluster for the given samples.

Parameters

Xpandas.DataFrame or numpy array

Test samples.

group_anumpy array

binary mask vector

group_bnumpy array

binary mask vector

Returns

numpy.ndarray

Predicted cluster per sample.

predict(X: ndarray)[source]#

Prediction

Description

Predict cluster for the given samples.

Parameters

Xpandas.DataFrame or numpy array

Test samples.

Returns

numpy.ndarray

Predicted output per sample.

set_fit_request(*, group_a: bool | None | str = '$UNCHANGED$', group_b: bool | None | str = '$UNCHANGED$') FairletClustering#

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters

group_astr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for group_a parameter in fit.

group_bstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for group_b parameter in fit.

Returns

selfobject

The updated object.