# 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(). See ReweighingMeta for a workaround.

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

 fit Only fit_transform() is allowed for this algorithm. fit_transform Compute the factors for reweighing the dataset and transform the sample weights. get_params Get parameters for this estimator. 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. tuple – Samples and their weights. X – Unchanged samples. sample_weight – Transformed sample weights.