holisticai.bias.mitigation.ExponentiatedGradientReduction
- class holisticai.bias.mitigation.ExponentiatedGradientReduction(*args, **kwargs)
Exponentiated gradient reduction 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.
References
Agarwal, Alekh, et al. “A reductions approach to fair classification.” International Conference on Machine Learning. PMLR, 2018.
- __init__(constraints: str = 'EqualizedOdds', eps: Optional[float] = 0.01, max_iter: Optional[int] = 50, nu: Optional[float] = None, eta0: Optional[float] = 2.0, loss: str = 'ZeroOne', min_val: Optional[float] = None, max_val: Optional[float] = None, upper_bound: float = 0.01, verbose: Optional[int] = 0)
Parameters
- estimator: An estimator implementing methods
fit(X, y, sample_weight)
andpredict(X)
, whereX
is the matrix of features,y
is the vector of labels, andsample_weight
is a vector of weights; labelsy
and predictions returned bypredict(X)
are either 0 or 1 – e.g. scikit-learn classifiers.- constraints (str or BaseMoment): If string, keyword
denoting the
BaseMoment
object defining the disparity constraints: [“DemographicParity”, “EqualizedOdds”, “TruePositiveRateParity”, “FalsePositiveRateParity”, “ErrorRateParity”,
]
- eps: 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 most2*(eps+best_gap)
.
T: Maximum number of iterations.
- nu: Convergence threshold for the duality gap, corresponding to a
conservative automatic setting based on the statistical uncertainty in measuring classification error.
eta_mul: Initial setting of the learning rate.
- drop_prot_attr: 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.
Methods
__init__
([constraints, eps, max_iter, nu, ...])Parameters
fit
(X, y_true, group_a, group_b)Fit Exponentiated Gradient Reduction
get_bias_param
(param_name[, default])get_estimator_param
(param_name[, default])get_params
([deep])Get parameters for this estimator.
has_param_handler
()link_parameters
(params_hdl)predict
(X)Prediction
Predict Probabilities
reformat_function
(func)score
(X, y[, sample_weight])Return the mean accuracy on the given test data and labels.
set_params
(**params)Set the parameters of this estimator.
transform_estimator
(estimator)update_bias_param
(param_name, param_value)update_estimator_param
(param_name, param_value)Attributes
BM_NAME
CONSTRAINTS
- fit(X: ndarray, y_true: ndarray, group_a: ndarray, group_b: ndarray)
Fit Exponentiated Gradient Reduction
Parameters
- Xmatrix-like
Input matrix
- y_truearray-like
Target vector
- group_aarray-like
Group membership vector (binary)
- group_barray-like
Group membership vector (binary)
Returns
Self
- get_params(deep=True)
Get parameters for this estimator.
Parameters
- deepbool, default=True
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Returns
- paramsdict
Parameter names mapped to their values.
- predict(X)
Prediction
Description
Predict output for the given samples.
Parameters
- Xmatrix-like
Input matrix.
Returns
numpy.ndarray: Predicted output
- predict_proba(X)
Predict Probabilities
Description
Probability estimate for the given samples.
Parameters
- Xmatrix-like
Input matrix.
Returns
numpy.ndarray: probability output
- score(X, y, sample_weight=None)
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Parameters
- Xarray-like of shape (n_samples, n_features)
Test samples.
- yarray-like of shape (n_samples,) or (n_samples, n_outputs)
True labels for X.
- sample_weightarray-like of shape (n_samples,), default=None
Sample weights.
Returns
- scorefloat
Mean accuracy of
self.predict(X)
wrt. y.
- set_params(**params)
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as
Pipeline
). The latter have parameters of the form<component>__<parameter>
so that it’s possible to update each component of a nested object.Parameters
- **paramsdict
Estimator parameters.
Returns
- selfestimator instance
Estimator instance.