aif360.sklearn.preprocessing
.Reweighing
- class aif360.sklearn.preprocessing.Reweighing(prot_attr=None)[source]
Sample reweighing.
Reweighing is a preprocessing technique that weights the examples in each (group, label) combination differently to ensure fairness before classification [1].
Note
This breaks the scikit-learn API by returning new sample weights from
fit_transform()
. SeeReweighingMeta
for a workaround.See also
References
- Variables:
prot_attr_ (str or list(str)) – Protected attribute(s) used for reweighing.
groups_ (array, shape (n_groups,)) – A list of group labels known to the transformer.
classes_ (array, shape (n_classes,)) – A list of class labels known to the transformer.
reweigh_factors_ (array, shape (n_groups, n_labels)) – Reweighing factors for each combination of group and class labels used to debias samples. Existing sample weights are multiplied by the corresponding factor for that sample’s group and class.
- Parameters:
prot_attr (single label or list-like, optional) – Protected attribute(s) to use in the reweighing process. If more than one attribute, all combinations of values (intersections) are considered. Default is
None
meaning all protected attributes from the dataset are used.
Methods
Only
fit_transform()
is allowed for this algorithm.Compute the factors for reweighing the dataset and transform the sample weights.
get_metadata_routing
Get metadata routing of this object.
get_params
Get parameters for this estimator.
Request metadata passed to the
fit
method.set_params
Set the parameters of this estimator.
- __init__(prot_attr=None)[source]
- Parameters:
prot_attr (single label or list-like, optional) – Protected attribute(s) to use in the reweighing process. If more than one attribute, all combinations of values (intersections) are considered. Default is
None
meaning all protected attributes from the dataset are used.
- fit(X, y, sample_weight=None)[source]
Only
fit_transform()
is allowed for this algorithm.
- fit_transform(X, y, sample_weight=None)[source]
Compute the factors for reweighing the dataset and transform the sample weights.
- Parameters:
X (pandas.DataFrame) – Training samples.
y (array-like) – Training labels.
sample_weight (array-like, optional) – Sample weights.
- Returns:
tuple – Samples and their weights.
X – Unchanged samples.
sample_weight – Transformed sample weights.
- set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') Reweighing [source]
Request metadata passed to the
fit
method.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 tofit
if 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.New 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:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weight
parameter infit
.- Returns:
self (object) – The updated object.