class fairlearn.reductions.DemographicParity(*, difference_bound=None, ratio_bound=None, ratio_bound_slack=0.0)[source]#

Implementation of demographic parity as a moment.

A classifier \(h(X)\) satisfies demographic parity if

\[P[h(X) = 1 | A = a] = P[h(X) = 1] \; \forall a\]

This implementation of UtilityParity defines a single event, all. Consequently, the prob_event pandas.Series will only have a single entry, which will be equal to 1. Similarly, the index property will have twice as many entries (corresponding to the Lagrange multipliers for positive and negative constraints) as there are unique values for the sensitive feature. The UtilityParity.signed_weights() method will compute the costs according to Example 3 of Agarwal et al.1.

This Moment also supports control features, which can be used to stratify the data, with the Demographic Parity constraint applied within each stratum, but not between strata. If the control feature groups are \(c \in \mathcal{C}\) then the above equation will become

\[P[h(X) = 1 | A = a, C = c] = P[h(X) = 1 | C = c] \; \forall a, c\]

Read more in the User Guide.


Return the number of samples in the data.



Return bound vector.


Return the default objective for moments of this kind.


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

load_data(X, y, *, sensitive_features[, ...])

Load the specified data into the object.


Return the projected lambda values.


Compute the signed weights.