fairlearn.reductions.ExponentiatedGradient#
- class fairlearn.reductions.ExponentiatedGradient(estimator, constraints, *, objective=None, eps=0.01, max_iter=50, nu=None, eta0=2.0, run_linprog_step=True, sample_weight_name='sample_weight')[source]#
An Estimator which implements the exponentiated gradient reduction.
Added in version 0.3.0.
The exponentiated gradient algorithm is described in detail by Agarwal et al.[1].
Read more in Passing pipelines to mitigation techniques.
Changed in version 0.3.0: Was a function before, not a class
Changed in version 0.4.6: Requires 0-1 labels for classification problems
- Parameters:
- estimatorestimator
An estimator implementing methods
fit(X, y, sample_weight)andpredict(X), where X is the matrix of features, y is the vector of labels (binary classification) or continuous values (regression), and sample_weight is a vector of weights. In binary classification labels y and predictions returned bypredict(X)are either 0 or 1. In regression values y and predictions are continuous.- constraintsfairlearn.reductions.Moment
The fairness constraints expressed as a
Moment.- objectivefairlearn.reductions.Moment |
None The objective expressed as a
Moment. The default isErrorRate()for binary classification andMeanLoss(...)for regression.- eps
float Allowed fairness constraint violation; the solution is guaranteed to have the error within
2*best_gapof the best error under constraint eps; the constraint violation is at most2*(eps+best_gap).Changed in version 0.5.0:
epsis now only responsible for setting the L1 norm bound in the optimization- max_iter
int Maximum number of iterations
Added in version 0.5.0: Used to be
T- nu
float|None Convergence threshold for the duality gap, corresponding to a conservative automatic setting based on the statistical uncertainty in measuring classification error
- eta0
float Initial setting of the learning rate
Added in version 0.5.0: Used to be
eta_mul- run_linprog_stepbool
if True each step of exponentiated gradient is followed by the saddle point optimization over the convex hull of classifiers returned so far; default True
Added in version 0.5.0.
- sample_weight_name
str Name of the argument to estimator.fit() which supplies the sample weights (defaults to sample_weight)
Added in version 0.5.0.
- fit(X, y, **kwargs)[source]#
Return a fair classifier under specified fairness constraints.
- Parameters:
- X
numpy.ndarrayorpandas.DataFrame Feature data
- y
numpy.ndarray,pandas.DataFrame,pandas.Series, orlist Label vector
- X
- get_metadata_routing()[source]#
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
- routingMetadataRequest
A
MetadataRequestencapsulating routing information.
- predict(X, random_state=None)[source]#
Provide predictions for the given input data.
Predictions are randomized, i.e., repeatedly calling predict with the same feature data may yield different output. This non-deterministic behavior is intended and stems from the nature of the exponentiated gradient algorithm.
- Parameters:
- X
numpy.ndarrayorpandas.DataFrame Feature data
- random_state
intorRandomStateinstance, default=None Controls random numbers used for randomized predictions. Pass an int for reproducible output across multiple function calls.
- X
- Returns:
- Scalar or vector
The prediction. If X represents the data for a single example the result will be a scalar. Otherwise the result will be a vector
Notes
A fitted ExponentiatedGradient has an attribute predictors_, an array of predictors, and an attribute weights_, an array of non-negative floats of the same length. The prediction on each data point in X is obtained by first picking a random predictor according to the probabilities in weights_ and then applying it. Different predictors can be chosen on different data points.
- set_params(**params)[source]#
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:
- **params
dict Estimator parameters.
- **params
- Returns:
- selfestimator instance
Estimator instance.
- set_predict_request(*, random_state: bool | None | str = '$UNCHANGED$') ExponentiatedGradient[source]#
Configure whether metadata should be requested to be passed to the
predictmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the 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.