holisticai.bias.mitigation.CalibratedEqualizedOdds#

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

Calibrated equalized odds postprocessing optimizes over calibrated classifier score outputs to find probabilities with which to change output labels with an equalized odds objective.

Parameters

cost_constraintstr

Strategy used to evalute the cost function The available contraints are: “fnr”, “fpr”, “weighted” false negative rate (fnr), false positive rate (fpr), and weighted

alphafloat

Used only with cost contraint “weighted”. Value between 0 and 1 used to combine fnr and fpr cost constraint.

seed: int

A seed value for random number generators. This ensures reproducibility of results.

Examples

>>> from holisticai.bias.mitigation import CalibratedEqualizedOdds
>>> mitigator = CalibratedEqualizedOdds(**params)
>>> mitigator.fit(y, y_proba, group_a, group_b)
>>> test_data_transformed = mitigator.predict(y_pred, y_proba, group_a, group_b)

References

fit(y: ndarray, y_proba: ndarray, group_a: ndarray, group_b: ndarray, sample_weight: ndarray | None = None)[source]#

Compute parameters for calibrated equalized odds.

Description

Compute parameters for calibrated equalized odds algorithm.

Parameters

yarray-like

Target vector

y_probamatrix-like

Predicted probability matrix (num_examples, num_classes). The probability estimates must sum to 1 across the possible classes and each matrix value must be in the interval [0,1].

group_aarray-like

Group membership vector (binary)

group_barray-like

Group membership vector (binary)

sample_weightarray-like

Sample weights. Used to weight generalized false positive rate (GFPR) and generalized false negative rate (GFNR). Sample weights could be used during training or computed by previous preprocessing strategy.

Returns

Self

fit_transform(y: ndarray, y_proba: ndarray, group_a: ndarray, group_b: ndarray, sample_weight: ndarray | None = None, threshold: float | None = 0.5)[source]#

Fit and transform

Description

Fit and transform

Parameters

yarray-like

Target vector

y_probamatrix-like

Predicted probability matrix (num_examples, num_classes). The probability estimates must sum to 1 across the possible classes and each matrix value must be in the interval [0,1].

group_aarray-like

Group membership vector (binary)

group_barray-like

Group membership vector (binary)

sample_weightarray-like

Sample weights. Used to weight generalized false positive rate (GFPR) and generalized false negative rate (GFNR). Sample weights could be used during training or computed by previous preprocessing strategy.

thresholdfloat

float value to discriminate between 0 and 1

Returns

dict

A dictionary of new predictions

transform(y_pred: ndarray, y_proba: ndarray, group_a: ndarray, group_b: ndarray, threshold: float | None = 0.5)[source]#

Apply transform function to predictions and likelihoods

Description

Use a fitted probability to change the output label and invert the likelihood

Parameters

y_predarray-like

Predicted vector (nb_examlpes,)

y_probamatrix-like

Predicted probability matrix (num_examples, num_classes). The probability estimates must sum to 1 across the possible classes and each matrix value must be in the interval [0,1].

group_aarray-like

Group membership vector (binary)

group_barray-like

Group membership vector (binary)

thresholdfloat

float value to discriminate between 0 and 1

Returns

dict

A dictionary of new predictions