holisticai.bias.mitigation.ExponentiatedGradientReduction#

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

Exponentiated gradient reduction

Exponentiated gradient reduction [1] is an in-processing technique that reduces fair classification to a sequence of cost-sensitive classification problems, returning a randomized classifier with the lowest empirical error subject to fair classification constraints.

Parameters

estimatorsklearn-like

The model you want to mitigate bias for.

constraints: str
The disparity constraints:
  • “DemographicParity”

  • “EqualizedOdds”

  • “TruePositiveRateParity”

  • “FalsePositiveRateParity”

  • “ErrorRateParity”

eps: float

Allowed fairness constraint violation; the solution is guaranteed to have the error within 2*best_gap of the best error under constraint eps; the constraint violation is at most 2*(eps+best_gap).

num_iter: int

Maximum number of iterations.

nu: float

Convergence threshold for the duality gap, corresponding to a conservative automatic setting based on the statistical uncertainty in measuring classification error.

eta_mul: float

Initial setting of the learning rate.

drop_prot_attr: bool

Boolean flag indicating whether to drop protected attributes from training data.

lossstr

String identifying loss function for constraints. Options include “ZeroOne”, “Square”, and “Absolute.”

min_valfloat

Loss function parameter for “Square” and “Absolute,” typically the minimum of the range of y values.

max_val: float

Loss function parameter for “Square” and “Absolute,” typically the maximum of the range of y values.

verboseint

If >0, will show progress percentage.

seed: int

seed for random initialization

Examples

>>> from holisticai.bias.mitigation import ExponentiatedGradientReduction
>>> mitigator = ExponentiatedGradientReduction(**params)
>>> mitigator.fit(train_data, y_data, group_a, group_b)
>>> test_data_transformed = mitigator.predict(test_data)

References

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

Fit Exponentiated Gradient Reduction

Parameters

Xmatrix-like

Input matrix

yarray-like

Target vector

group_aarray-like

Group membership vector (binary)

group_barray-like

Group membership vector (binary)

Returns

Self

predict(X)[source]#

Prediction

Description

Predict output for the given samples.

Parameters

Xmatrix-like

Input matrix.

Returns

numpy.ndarray: Predicted output

predict_proba(X)[source]#

Predict Probabilities

Description

Probability estimate for the given samples.

Parameters

Xmatrix-like

Input matrix.

Returns

numpy.ndarray: probability output

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

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.

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') ExponentiatedGradientReduction#

Request metadata passed to the score 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 score 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 score.

  • 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

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

Metadata routing for sample_weight parameter in score.

Returns

selfobject

The updated object.

transform_estimator(estimator)[source]#

This method is deprecated but retained for backwards-compatibility. You should pass the estimator object directly in the constructor.