holisticai.bias.mitigation.VariationalFairClustering#
- class holisticai.bias.mitigation.VariationalFairClustering(*args, **kargs)[source]#
Variational Fair Clustering [1] helps you to find clusters with specified proportions of different demographic groups pertaining to a sensitive attribute of the dataset (group_a and group_b) for any well-known clustering method such as K-means, K-median or Spectral clustering (Normalized cut).
Parameters
- n_clustersint
The number of clusters to form as well as the number of centroids to generate.
- lipchitz_valuefloat
Lipchitz value in bound update
- lmbdafloat
specified lambda parameter
- methodstr
cluster option : {‘kmeans’, ‘kmedian’}
- normalize_inputstr
Normalize input data X
- seedint
Random seed.
- verbosebool
If true , print metrics
Examples
>>> from holisticai.bias.mitigation import VariationalFairClustering >>> mitigator = VariationalFairClustering(**params) >>> mitigator.fit(train_data, group_a, group_b) >>> test_data_transformed = mitigator.predict(test_data, group_a, group_b)
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, group_a: ndarray, group_b: ndarray)[source]#
Prediction
Description
Predict 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 output per sample.
- set_fit_request(*, group_a: bool | None | str = '$UNCHANGED$', group_b: bool | None | str = '$UNCHANGED$') VariationalFairClustering#
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.
- set_predict_request(*, group_a: bool | None | str = '$UNCHANGED$', group_b: bool | None | str = '$UNCHANGED$') VariationalFairClustering#
Request metadata passed to the
predictmethod.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 topredictif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it topredict.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 inpredict.- group_bstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
group_bparameter inpredict.
Returns
- selfobject
The updated object.