fairlearn.reductions.Moment#

class fairlearn.reductions.Moment[source]#

Generic moment.

Our implementations of the reductions approach to fairness [1] make use of Moment objects to describe both the optimization objective and the fairness constraints imposed on the solution. This is an abstract class for all such objects.

Read more in the User Guide.

Added in version 0.3.0.

bound()[source]#

Return vector of fairness bound constraint the length of gamma.

Return type:

Series

Returns:

The upper bound for each constraint, indexed by index. The entries of gamma() are compared against these values.

default_objective()[source]#

Return the default objective for the moment.

Return type:

Moment

gamma(predictor)[source]#

Calculate the degree to which constraints are currently violated by the predictor.

Parameters:

predictor (Callable) – A function that maps the feature matrix to predictions.

Return type:

Series

Returns:

The value of each constraint for the predictor, indexed by index. The constraints are satisfied when these values do not exceed the values returned by bound().

load_data(X, y, *, sensitive_features=None)[source]#

Load a set of data for use by this object.

Parameters:
  • X (array) – The feature array

  • y (Series) – The label vector

  • sensitive_features (Series | None) – The sensitive feature vector (default None)

Return type:

None

project_lambda(lambda_vec)[source]#

Return the projected lambda values.

Parameters:

lambda_vec (Series) – The vector of Lagrange multipliers, indexed by index.

Return type:

Series

Returns:

Lagrange multipliers that give the same or a higher Lagrangian value than lambda_vec for every predictor and may have a smaller L1 norm. They are used by the ExponentiatedGradient algorithm when evaluating the Lagrangian.

signed_weights(lambda_vec)[source]#

Return the signed weights.

Parameters:

lambda_vec (Series) – The vector of Lagrange multipliers, indexed by index.

Return type:

Series

Returns:

One weight per sample. For classification, reductions add the objective and constraint weights, use the sign of the sum to choose a binary label for the cost-sensitive learning problem, and use its absolute value as the sample weight for the underlying estimator. For regression, the original target values are kept and the weights are used to reweight samples. GridSearch omits separate objective weights when the objective is already in the span of the constraints.

property index: MultiIndex | Index#

Return a pandas (multi-)index listing the constraints.

property total_samples: int#

Return the number of samples in the data.