Simple Algorithm
Artificial Intelligence · Deep Layer · 24 min

Bias Mitigation Techniques

Pre-, in- and post-processing interventions.

An audit finds a disparity. You can change the data, the training objective or the decisions, and each lever has a precise form with a guarantee: reweighing makes the label independent of the group, the reductions approach turns any classifier learner into a fair one with provable error, and group-specific thresholds reach equal error rates at the least cost a given score allows. Counterfactual fairness asks a different, causal question. Every lever also has a price, and this lesson computes it.

What you’ll learn

  • Derive reweighing weights, prove that they make the group and the label independent while preserving both marginals, and explain what pre-processing cannot guarantee.
  • Formulate fair classification as a saddle-point problem, describe the exponentiated-gradient reduction, and prove the error and violation guarantees of an approximate saddle point.
  • Derive equalized-odds post-processing as a linear program over ROC curves, and quantify its cost, including leveling down, in the widget.
  • Define counterfactual fairness, prove the non-descendant sufficient condition, and summarize the main critiques.

Where to intervene

StageWhat changesNeeds AA when deciding?What is guaranteedExamples
Pre-processingthe training data or featuresnoproperties of the data, such as A⊥ ⁣ ⁣ ⁣⊥YA\indep Y, not of the classifierreweighing, fair representations, disparate-impact repair
In-processingthe learning objectivenot necessarilyconstraints on the training distribution, with generalization boundsthe reductions approach, adversarial debiasing
Post-processingthe decision rule applied to a fixed scoreyesthe chosen criterion, exactly, on the data used to fit itgroup-specific thresholds (Hardt, Price & Srebro, 2016)
All three need the group attribute during development, to fit or at least to audit; they differ in whether the deployed rule uses it.

Law shapes the choice. Post-processing applies different thresholds to different groups, an explicit use of the group attribute at decision time, and in US employment testing the Civil Rights Act of 1991 forbids adjusting scores or using different cutoffs by race, color, religion, sex or national origin. Using AA only during training avoids that explicit use, but Lipton, McAuley & Chouldechova (2018) show that when other features reveal group membership, such "disparate learning processes" implement group-dependent treatment indirectly, discriminate within groups, and trade accuracy for parity worse than an open, group-aware rule.

Pre-processing: reweighing and representations

DerivationReweighing (Kamiran & Calders, 2012)
  1. ∑a,yw(a,y) P(a,y)=∑a,yP(a) P(y)=1\sum_{a,y}w(a,y)\,P(a,y)=\sum_{a,y}P(a)\,P(y)=1

    Give each training example in the cell (A,Y)=(a,y)(A,Y)=(a,y) the weight w(a,y)=Pr⁡(A=a)Pr⁡(Y=y)/Pr⁡(A=a,Y=y)w(a,y)=\Pr(A=a)\Pr(Y=y)/\Pr(A=a,Y=y), estimated from counts. The reweighted distribution Q(x,a,y)=w(a,y) P(x,a,y)Q(x,a,y)=w(a,y)\,P(x,a,y) is already normalized:

  2. Q(a,y)=w(a,y)P(a,y)=P(a)P(y),Q(a)=∑yP(a)P(y)=P(a),Q(y)=P(y)Q(a,y)=w(a,y)P(a,y)=P(a)P(y),\qquad Q(a)=\sum_yP(a)P(y)=P(a),\qquad Q(y)=P(y)

    Its cell probabilities factorize, so under QQ the label is independent of the group, and both marginals are unchanged:

  3. Q(x∣a,y)=w(a,y)P(x,a,y)w(a,y)P(a,y)=P(x∣a,y)Q(x\mid a,y)=\frac{w(a,y)P(x,a,y)}{w(a,y)P(a,y)}=P(x\mid a,y)

    Within a cell nothing changes, so reweighing only rebalances how much each (group, outcome) combination counts in the loss:

Predict before you look

In the loan data of Bias & Fairness, the groups are equal in size, and 50% of A and 30% of B would repay, so 40% overall. What weight does reweighing give a repayer in group B?

Show the answer

1.33

w=Pr⁡(B)Pr⁡(Y=1)/Pr⁡(B,Y=1)=0.5×0.4/(0.5×0.3)=4/3w=\Pr(B)\Pr(Y=1)/\Pr(B,Y=1)=0.5\times0.4/(0.5\times0.3)=4/3. The other weights are 0.8 for repayers in A, 1.2 for defaulters in A and 6/7≈0.866/7\approx0.86 for defaulters in B. Under these weights both groups repay at 40%.

What reweighing does not do: a classifier trained on QQ still sees features whose distribution differs by group, so its predictions need not satisfy parity, and no reweighting repairs a label that is itself biased. Representation methods go further and learn features Z=g(X)Z=g(X) that predict YY but carry little information about AA, either by mapping individuals to prototypes under an objective that balances reconstruction, prediction and parity (learning fair representations; Zemel et al., 2013) or by training against an adversary that tries to recover AA from ZZ (Edwards & Storkey, 2016; Madras et al., 2018). If Z⊥ ⁣ ⁣ ⁣⊥AZ\indep A exactly, every classifier built on ZZ satisfies demographic parity, and nothing more. In practice adversarial removal often leaves group information that a fresh classifier can still extract (Elazar & Goldberg, 2018). Feldman et al. (2015) instead "repair" each feature by mapping every group's quantiles onto a common distribution, which removes the feature's marginal information about AA while preserving ranks within groups.

In-processing: fair classification as a game

Agarwal, Beygelzimer, Dudík, Langford & Wallach (2018) handle any constraint that is linear in conditional moments of the predictions. A randomized classifier QQ is a distribution over a class H\mathcal H, and the constraints read γ(Q)≤c\gamma(Q)\le c, with γk(Q)=E[gk(X,A,Y,h(X))∣Ek]\gamma_k(Q)=\E\big[g_k(X,A,Y,h(X))\mid\mathcal E_k\big] averaged over h∼Qh\sim Q. Demographic parity, for instance, is the pair of constraints ±(E[h(X)∣A=a]−E[h(X)])≤ε\pm\big(\E[h(X)\mid A=a]-\E[h(X)]\big)\le\varepsilon for each group, and equalized odds conditions on YY as well. Fair classification becomes

min⁡Q∈Δ(H) max⁡λ∈Λ L(Q,λ)=err(Q)+λ⊤(γ(Q)−c),Λ={λ∈R≥0K:∥λ∥1≤B}\min_{Q\in\Delta(\mathcal H)}\ \max_{\lambda\in\Lambda}\ L(Q,\lambda)=\mathrm{err}(Q)+\lambda^\top\big(\gamma(Q)-c\big),\qquad\Lambda=\big\{\lambda\in\R^K_{\ge0}:\norm\lambda_1\le B\big\}
A zero-sum game between a learner choosing QQ and an auditor choosing prices λ\lambda for the constraints. LL is linear in both, so a saddle point exists, and in general it requires a randomized classifier.
text
function EXPONENTIATED-GRADIENT(data, BEST, B, η, ν):
    θ ← 0 ∈ R^K                                  # log-prices of the K constraints
    for t = 1, 2, …:
        λ(t) ← B · exp(θ) / (1 + Σ_k exp(θ_k))   # prices in the scaled simplex
        h(t) ← BEST(λ(t))       # minimizes err(h) + λ(t)ᵀγ(h): a cost-sensitive
                                # (reweighted, relabeled) classification problem
        Q̂ ← uniform mixture of h(1..t);   λ̂ ← average of λ(1..t)
        if (Q̂, λ̂) is a ν-approximate saddle point: return Q̂
        θ ← θ + η · (γ(h(t)) − c)                # raise the price of violated constraints

Because L(h,λ)L(h,\lambda) is linear in the predictions h(x)h(x), the learner's best response is a weighted classification problem: each example gets a cost for predicting 0 and a cost for predicting 1, and any classifier that accepts example weights can solve it. That is the reduction. Agarwal et al. show that a ν\nu-approximate saddle point is reached within O(B2log⁡K/ν2)\order{B^2\log K/\nu^2} iterations, up to a factor for the scale of the constraints, and add finite-sample guarantees. The method is implemented in the open-source Fairlearn library.

DerivationProof
  1. err(Q^)−ν≤L(Q^,λ^)≤err(Q∗)+λ^⊤(γ(Q∗)−c)+ν≤err(Q∗)+ν\mathrm{err}(\hat Q)-\nu\le L(\hat Q,\hat\lambda)\le\mathrm{err}(Q^*)+\hat\lambda^\top\big(\gamma(Q^*)-c\big)+\nu\le\mathrm{err}(Q^*)+\nu

    Error. Take λ=0\lambda=0 in the auditor's inequality and Q=Q∗Q=Q^* in the learner's. Since λ^≥0\hat\lambda\ge0 and γ(Q∗)−c≤0\gamma(Q^*)-c\le0, the price term at Q∗Q^* is at most zero:

  2. err(Q^)+Bv−ν≤L(Q^,λ^)≤err(Q∗)+ν\mathrm{err}(\hat Q)+Bv-\nu\le L(\hat Q,\hat\lambda)\le\mathrm{err}(Q^*)+\nu

    Violation. Let v=max⁡k(γk(Q^)−ck)v=\max_k\big(\gamma_k(\hat Q)-c_k\big) and suppose v>0v>0. Put the whole budget on the most violated constraint, λ=Bek∗\lambda=Be_{k^*}, in the auditor's inequality, and again take Q=Q∗Q=Q^* in the learner's:

  3. v≤1+2νB■v\le\frac{1+2\nu}{B}\qquad\blacksquare

    Errors lie in [0,1][0,1], so Bv≤err(Q∗)−err(Q^)+2ν≤1+2νBv\le\mathrm{err}(Q^*)-\mathrm{err}(\hat Q)+2\nu\le1+2\nu. A larger price budget BB tightens the constraints but slows convergence, the trade-off visible in the iteration count.

Adversarial debiasing (Zhang, Lemoine & Mitchell, 2018) is the deep-learning cousin: the predictor minimizes its loss while an adversary tries to predict AA from the prediction, and from YY as well when the target is equalized odds. It scales to large networks but comes with no comparable guarantee.

Post-processing: thresholds and ROC geometry

Hardt, Price & Srebro (2016) start from a fixed score RR and the group attribute, and derive a randomized decision Y~\tilde Y that depends only on (R,A)(R,A). Within group aa, each threshold gives a point (FPR, TPR) on the group's ROC curve, and randomizing between two thresholds reaches every point of the segment between them, so the achievable points form the convex hull CaC_a of the curve. Equalized odds asks for one common point in CA∩CBC_A\cap C_B; equal opportunity only for equal TPRs.

max⁡(f,τ)∈CA∩CB ∑aPr⁡(A=a)[pa τ+(1−pa)(1−f)]\max_{(f,\tau)\in C_A\cap C_B}\ \sum_a\Pr(A=a)\big[p_a\,\tau+(1-p_a)(1-f)\big]
Accuracy under equalized odds: a linear objective over a convex polygon, maximized at a vertex by a linear program. Hardt et al. also show that post-processing the Bayes-optimal score Pr⁡(Y=1∣X,A)\Pr(Y=1\mid X,A) loses nothing: the best equalized-odds predictor derived from it is optimal among all equalized-odds predictors. A weaker score passes its weaknesses on.
DerivationPost-processing the loan data
  1. max⁡(f,τ)∈CB 0.4 τ+0.6 (1−f)⟹the vertex of CB where the hull’s slope crosses 1.5\max_{(f,\tau)\in C_B}\ 0.4\,\tau+0.6\,(1-f)\quad\Longrightarrow\quad\text{the vertex of }C_B\text{ where the hull's slope crosses }1.5

    In the loan data of Bias & Fairness, group A's ROC curve lies above B's at every false-positive rate, so CB⊂CAC_B\subset C_A and the feasible set is B's hull. With equal group sizes and base rates 0.5 and 0.3, the objective is 0.4τ+0.6(1−f)0.4\tau+0.6(1-f), whose level lines have slope 0.6/0.4=1.50.6/0.4=1.5 in ROC space:

  2. accA=0.5 (0.567)+0.5 (0.857)≈71.2%,accB=0.3 (0.567)+0.7 (0.857)≈77.0%\mathrm{acc}_A=0.5\,(0.567)+0.5\,(0.857)\approx71.2\%,\qquad\mathrm{acc}_B=0.3\,(0.567)+0.7\,(0.857)\approx77.0\%

    That vertex is B's threshold 58, with FPR 14.3% and TPR 56.7%. Group A must land on the same point, which it can do only by randomizing between two of its thresholds, deliberately making its decisions noisier:

  3. Overall accuracy is 74.1%, better than the 67.3% of the best deterministic equalized-odds thresholds. But A's accuracy falls from 86.0% to 71.2% and its repayers' approval rate from 90% to 57%, while B's accuracy moves from 77.5% to 77.0%. Equality is reached by making one group worse off with no gain for the other, which critics call leveling down.

Is the price of equalized odds a base-rate effect? The widget below gives both groups the same base rate, 50%, but keeps group B's noisier scores.

Counterfactual fairness

Proof. Intervening on AA changes only AA's descendants. For a non-descendant WW, WA←a′(u)=W(u)W_{A\leftarrow a'}(u)=W(u) for every uu, so Y^A←a′(u)=f(W(u))=Y^A←a(u)\hat Y_{A\leftarrow a'}(u)=f(W(u))=\hat Y_{A\leftarrow a}(u) for every uu, and the two conditional distributions coincide. ■\blacksquare In Kusner et al.'s law-school example, undergraduate GPA and the admission-test score both depend on race, sex and an unobserved "knowledge" KK. A predictor of first-year grades built on the raw scores is not counterfactually fair, because both scores are descendants of race. One built on KK, inferred from the observed scores through the causal model, is fair by the lemma, and in their experiments it gave up some accuracy.

The approach inherits every assumption of the causal model, which usually cannot be identified from data, and different plausible graphs give different verdicts. Treating race as a variable one can intervene on is itself contested: Kohler-Hausmann (2019) argues that race is a social category constituted by many of the very features a counterfactual would hold fixed or change, so "the same person with a different race" is not well defined. Path-specific variants (Nabi & Shpitser, 2018; Chiappa, 2019) let some causal paths from AA count as acceptable, for example through a chosen field of study, at the cost of deciding which paths those are.

Key takeaways

  • Pre-, in- and post-processing intervene on the data, the objective and the decisions; they differ in when they need AA, in what they guarantee, and in how they interact with anti-discrimination law.
  • Reweighing by P(a)P(y)/P(a,y)P(a)P(y)/P(a,y) makes AA and YY independent while preserving both marginals, but guarantees nothing about predictions; invariant representations guarantee parity at most.
  • The reductions approach solves min⁡Qmax⁡λerr(Q)+λ⊤(γ(Q)−c)\min_Q\max_\lambda\mathrm{err}(Q)+\lambda^\top(\gamma(Q)-c) with exponentiated gradient and a cost-sensitive oracle; a ν\nu-approximate saddle point has error within 2ν2\nu of the best feasible classifier and violations of at most (1+2ν)/B(1+2\nu)/B.
  • Post-processing picks a point in the intersection of the groups' ROC hulls by linear programming. When one group's score is less informative, equal error rates are reached by leveling the other group down.
  • Counterfactual fairness asks whether an individual's prediction would change under a different group attribute; functions of non-descendants of AA satisfy it, but the verdict depends on a contested causal model.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

Reweighing with w(a,y)=P(a)P(y)/P(a,y)w(a,y)=P(a)P(y)/P(a,y) guarantees which of the following?

  1. Demographic parity of the trained classifier's predictions
  2. Independence of AA and YY in the reweighted training distribution, with both marginals unchanged
  3. Equalized odds of the trained classifier
  4. That biased labels are corrected
Show the answer

B. Independence of AA and YY in the reweighted training distribution, with both marginals unchanged

Q(a,y)=P(a)P(y)Q(a,y)=P(a)P(y) by construction, while Q(a)=P(a)Q(a)=P(a), Q(y)=P(y)Q(y)=P(y) and Q(x∣a,y)=P(x∣a,y)Q(x\mid a,y)=P(x\mid a,y). That is a property of the training data. The classifier still sees group-dependent features, so properties of its predictions must be checked separately.

Question 2

Why does the reductions approach return a randomized classifier, a mixture over h∈Hh\in\mathcal H?

  1. Randomness always improves accuracy
  2. The constrained problem is a game that is linear in distributions over H\mathcal H; mixtures convexify it, and a single deterministic classifier may not reach the same error and constraint values
  3. The cost-sensitive oracle is itself random
  4. Randomization is required for privacy
Show the answer

B. The constrained problem is a game that is linear in distributions over H\mathcal H; mixtures convexify it, and a single deterministic classifier may not reach the same error and constraint values

Error and the moment constraints are linear in QQ, so the feasible set of mixtures is convex and the Lagrangian game has a saddle point among them; exponentiated gradient's output is the average of the best responses. Deterministic classifiers form a non-convex set on which the same trade-off may be unattainable.

Question 3

In the loan data, randomized post-processing for equalized odds raises overall accuracy from 67.3%, with the best deterministic thresholds, to 74.1%. What happens to each group compared with its own most accurate thresholds?

  1. Both groups become more accurate
  2. Group A's accuracy falls from 86.0% to 71.2% and its repayers' approval rate from 90% to 57%, while group B stays near its best (77.0% against 77.5%)
  3. Group B gains about 10 points of accuracy
  4. Nothing changes for group A
Show the answer

B. Group A's accuracy falls from 86.0% to 71.2% and its repayers' approval rate from 90% to 57%, while group B stays near its best (77.0% against 77.5%)

B's ROC curve lies below A's, so the common operating point must lie on B's hull, at B's threshold 58. A can reach that point only by randomizing, which makes its decisions noisier. Equality is bought by lowering A to B's level: leveling down.

Question 4

Which predictor is guaranteed to be counterfactually fair?

  1. One that excludes AA from its inputs
  2. One that satisfies demographic parity
  3. One that is calibrated within groups
  4. One that is a function only of variables that are not descendants of AA in the causal graph
Show the answer

D. One that is a function only of variables that are not descendants of AA in the causal graph

Intervening on AA changes only its descendants, so a function of non-descendants takes the same value for every uu in the actual and the counterfactual world. Excluding AA is not enough: features caused by AA carry its effect.

Further reading

  • F. Kamiran & T. Calders, "Data preprocessing techniques for classification without discrimination," Knowledge and Information Systems (2012).
  • A. Agarwal, A. Beygelzimer, M. Dudík, J. Langford & H. Wallach, "A reductions approach to fair classification," ICML (2018).
  • M. Hardt, E. Price & N. Srebro, "Equality of opportunity in supervised learning," NeurIPS (2016).
  • M. J. Kusner, J. Loftus, C. Russell & R. Silva, "Counterfactual fairness," NeurIPS (2017).
  • N. Mehrabi, F. Morstatter, N. Saxena, K. Lerman & A. Galstyan, "A survey on bias and fairness in machine learning," ACM Computing Surveys (2021).