holisticai.bias.mitigation.GridSearchReduction#

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

Grid Search Reduction technique can be used for fair classification or fair regression.

  1. For classification it reduces fair classification to a sequence of cost-sensitive classification problems, returning the deterministic classifier with the lowest empirical error subject to fair classification constraints among the candidates searched [1].

  2. For regression it uses the same priniciple to return a deterministic regressor with the lowest empirical error subject to the constraint of bounded group loss [2].

Parameters

constraintsstring
The disparity constraints expressed as string:
  • “DemographicParity”,

  • “EqualizedOdds”,

  • “TruePositiveRateParity”,

  • “FalsePositiveRateParity”,

  • “ErrorRateParity”

  • “BoundedGroupLoss”

constraint_weightfloat

Specifies the relative weight put on the constraint violation when selecting the best model. The weight placed on the error rate will be 1-constraint_weight

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.

grid_sizeint

The number of Lagrange multipliers to generate in the grid

grid_limitfloat

The largest Lagrange multiplier to generate. The grid will contain values distributed between -grid_limit and grid_limit by default

verboseint

If >0, will show progress percentage.

Examples

>>> from holisticai.bias.mitigation import GridSearchReduction
>>> mitigator = GridSearchReduction(**params)
>>> mitigator.fit(train_data, y, 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 model using Grid Search 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]#

Probability Prediction

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$') GridSearchReduction#

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.