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
fitmethod.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 tofitif 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.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_aparameter infit.- group_bstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
group_bparameter infit.
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_probamethod.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 topredict_probaif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it topredict_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_aparameter inpredict_proba.- group_bstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
group_bparameter inpredict_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
predictmethod.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 topredictif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it topredict.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_aparameter inpredict.- group_bstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
group_bparameter inpredict.
Returns
- selfobject
The updated object.
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') PrejudiceRemover#
Request metadata passed to the
scoremethod.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 toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.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_weightparameter inscore.
Returns
- selfobject
The updated object.