holisticai.bias.mitigation.FairKCenterClustering#
- class holisticai.bias.mitigation.FairKCenterClustering(*args, **kargs)[source]#
Fair K-Center Clustering
Fair K-Center Clustering [1] inprocessing bias mitigation implements an approximation algorithm for the k-centers problem under the fairness contraint with running time linear in the size of the dataset and k (number of cluster).
Parameters
- req_nr_per_grouplist
Number of cluster for each group that will be founded.
Integer-vector of length m with entries in 0,…,k.
Sum of all entries must be equal to k (total number of clusters).
- nr_initially_givenint
Number of initial random centers.
- strategystr
Strategy used to compute the cluster centers. Available are:
‘Fair K-Center’ (default)
‘Heuristic Greedy by Group’
‘Heuristic Greedy by Constraint’
- seedint,
Initial random seed.
Examples
>>> from holisticai.bias.mitigation import FairKCenterClustering >>> mitigator = FairKCenterClustering(**params) >>> mitigator.fit(train_data, group_a, group_b) >>> test_data_transformed = mitigator.predict(test_data, group_a, group_b)
References
- fit(X, group_a, group_b)[source]#
Fit model using Fair K-Center Clustering.
Parameters
- Xmatrix-like
Input matrix
- group_aarray-like
Group membership vector (binary)
- group_barray-like
Group membership vector (binary)
Returns
Self
- predict(X)[source]#
Predict the closest cluster each sample in X belongs to.
Parameters
- Xmatrix-like
Input matrix
Returns
- numpy array
A distance matrix between the samples and the clusters.
- set_fit_request(*, group_a: bool | None | str = '$UNCHANGED$', group_b: bool | None | str = '$UNCHANGED$') FairKCenterClustering#
Request metadata passed to the
fitmethod.Note that this method is only relevant if
enable_metadata_routing=True(seesklearn.set_config()). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.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_aparameter infit.- group_bstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
group_bparameter infit.
Returns
- selfobject
The updated object.