holisticai.bias.mitigation.PrejudiceRemover#

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

Prejudice Remover

Prejudice remover [1] is an in-processing technique that adds a discrimination-aware regularization term to the learning objective.

Parameters

etafloat

fairness penalty parameter

Cfloat

Inverse of regularization strength (same as sklearn).

fit_interceptbool

Specifies if a constant must be added to the decision function (same as sklearn).

penaltystr

Specify the norm of the penalty (same as sklearn).

init_typestr

Specifies how the model parameters will be initialized: - Zero : Set all model parameters with zero value. - Random : Initialize model parameters with random values. - StandarLR : Initialize model parameters with fitted sklearn LR. - StandarLRbyGroup : Initialize model parameters with fitted sklearn LR for group_a and group_b.

maxiterstr

Maximum number of iterations.

verboseint

Log progress if value > 0.

print_intervalint

Each print_interval steps print information.

Examples

>>> from holisticai.bias.mitigation import PrejudiceRemover
>>> mitigator = PrejudiceRemover(**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 the model

Description

Learns the regularized logistic regression model.

Parameters

Xndarray

input data

yndarray

Target vector

group_andarray

group mask

group_bndarray

group mask

Returns

Self

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

Prediction

Description

Predict output for the given samples.

Parameters

Xpandas.DataFrame or numpy array

Test samples.

group_andarray

group mask

group_bndarray

group mask

Returns

numpy.ndarray

Predicted output per sample.

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

Prediction

Description

Predict output for the given samples.

Parameters

Xnumpy array

Test samples.

group_andarray

group mask

group_bndarray

group mask

Returns

numpy.ndarray

Predicted output per sample.

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

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_predict_proba_request(*, group_a: bool | None | str = '$UNCHANGED$', group_b: bool | None | str = '$UNCHANGED$') PrejudiceRemover#

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

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

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

Metadata routing for group_b parameter in predict_proba.

Returns

selfobject

The updated object.

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

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

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

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

Metadata routing for group_b parameter in predict.

Returns

selfobject

The updated object.

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

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=None)[source]#

Transform estimator

Description

Transform the estimator to the Prejudice Remover model.

Parameters

estimatorobject (optional)

Estimator to be transformed.

Returns

self