Fairness & Explainability
- ProPublica COMPAS analysis (2016) showed a recidivism prediction model was biased against Black defendants - triggering the algorithmic fairness research field
- Chouldechova (2017) proved that three intuitive fairness criteria are mutually incompatible except in degenerate cases
- GDPR (2018) mandated the right to explanation for algorithmic decisions in the EU
Algorithmic fairness requires that model predictions do not systematically disadvantage protected groups (demographic parity, equal opportunity). Explainability requires that model decisions can be understood and audited. SHAP, LIME, and integrated gradients are the main post-hoc explanation methods.
- Fairness metrics connect to evaluation metrics - they are performance metrics disaggregated by group
- SHAP values connect to game theory (Shapley values from cooperative game theory)
- Differential privacy and federated learning are technical tools for privacy-preserving fairness
- Define demographic parity, equalized odds, equal opportunity, and calibration and state which pairs are mutually exclusive.
- Sketch the proof of the fairness impossibility theorem (Chouldechova / Kleinberg) and state when the constraints can all hold.
- Derive the Shapley value formula from first principles and explain how SHAP estimates it for ML models.
- Distinguish integrated gradients from vanilla gradients and explain the completeness and sensitivity axioms.
- State the epsilon-delta definition of differential privacy and explain the privacy-accuracy trade-off in DP-SGD.
TL;DR
Fairness and explainability are complementary safety concerns for deployed ML systems. Fairness definitions formalise what it means for a model to treat groups equitably, but Chouldechova [1] and Kleinberg et al. [2] proved that several natural fairness criteria are mathematically incompatible when base rates differ across groups. Explainability methods---SHAP [3], LIME [4], Integrated Gradients [5]---attribute model predictions to input features, but Jain and Wallace [6] showed that attention weights are not faithful explanations of model behaviour. Privacy-preserving learning (differential privacy [7], federated learning [8]) addresses data governance rather than model behaviour, but is increasingly required alongside fairness and explainability for regulatory compliance.
Fairness definitions
A fairness criterion is a mathematical constraint on the joint distribution of predictions, true labels, and sensitive attributes (race, gender, age, etc.). Different criteria formalise different conceptions of fairness.
Demographic parity (statistical parity): the prediction is independent of the sensitive attribute :
Both groups receive positive predictions at equal rates. This is the baseline intuition for “equal treatment” but ignores whether the base rates of the true outcome differ.
Equal opportunity (Hardt et al. 2016): the true positive rate is equal across groups:
Qualified members of each group are equally likely to receive a positive prediction.
Equalized odds: both the true positive rate AND the false positive rate are equal across groups:
This is stricter than equal opportunity.
Calibration: the predicted probability equals the empirical fraction of positives, separately for each group:
A calibrated model means “if I say there’s a 70% chance, 70% of such cases really do belong to the positive class”, within each group.
The fairness impossibility theorem
Chouldechova [1] and Kleinberg et al. [2] independently proved that calibration, balance for the positive class, and balance for the negative class cannot all hold simultaneously unless the base rates are equal across groups.
Informal proof sketch. For group , let:
- (base rate)
- (positive predictive value)
- (false positive rate)
- (false negative rate)
From Bayes’ theorem and basic probability identities, one can derive:
If both groups have equal FPR and FNR (equalized odds), but , then the PPV values differ across groups. A model that satisfies equalized odds therefore cannot satisfy predictive parity (equal PPV) unless .
Conversely, if both groups have equal PPV (calibration) and the false positive rates are equal, then the false negative rates must differ when the base rates differ.
Practical implication. In criminal recidivism prediction: if Black defendants have a higher base rate of recidivism (due to structural factors including prior over-policing), a calibrated model will have equal PPV across groups but will have higher false positive rates for white defendants or higher false negative rates for Black defendants, or some combination. There is no statistically fair solution if the base rates reflect historical injustice.
The theorem does not say that fairness is impossible; it says that you must choose which fairness criterion to optimise, and that choice is a value judgment, not a technical one.
SHAP: Shapley value attribution
SHAP [3] attributes the prediction to individual input features by computing Shapley values from cooperative game theory.
Shapley value derivation
For a model and an input , the Shapley value of feature is defined as the average marginal contribution of feature across all possible orderings of features:
where is the expected model output when the features in are observed and the rest are marginalised out.
Four axioms uniquely characterise the Shapley value:
- Efficiency: . Attributions sum to the model’s output relative to the base value.
- Symmetry: if features and contribute equally to all subsets, .
- Dummy: if feature never changes the output, .
- Additivity: for two models , .
Computational complexity. The exact Shapley value requires evaluations of ---exponential in the number of features. SHAP approximates it:
- KernelSHAP: model-agnostic; samples subsets and fits a weighted linear model. worst case but efficient in practice for .
- TreeSHAP: exact for tree-based models (decision trees, XGBoost, LightGBM) in where is the number of trees, is the number of leaves, and is the tree depth. This is the production workhorse for tabular ML.
- DeepSHAP: uses DeepLIFT-style backpropagation to approximate Shapley values for neural networks.
LIME: local linear approximations
LIME [4] explains a single prediction by approximating the model locally with an interpretable model (a linear model or decision tree).
For an input and a black-box model , LIME:
- Samples perturbed inputs near (for text: randomly mask tokens; for images: randomly grey-out superpixels).
- Gets model predictions for each perturbed input.
- Weights each by its proximity to : .
- Fits a linear model to minimise plus a complexity penalty.
The coefficients of are the local feature importances. LIME is model-agnostic and local: it explains one prediction at a time and makes no assumptions about .
Limitations: (1) Instability---the explanation can vary significantly between runs because the perturbation is random. (2) Distribution shift---perturbed samples may be out-of-distribution (grey-ed out pixels do not look like realistic images), so may not reflect model behaviour on realistic inputs. (3) Approximation error---the local linear approximation may be poor if is highly nonlinear near .
Integrated gradients
Integrated Gradients (IG) [5] attributes predictions using the path integral of gradients from a baseline input (e.g., all zeros) to the actual input :
In practice the integral is approximated by summing over evenly-spaced steps along the path from to .
Axioms satisfied by IG:
- Completeness: . The attributions sum to the model output difference between input and baseline. This is the key advantage over vanilla gradients, which only reflect local sensitivity and do not integrate to the output.
- Sensitivity: if and and differ in exactly one feature, that feature gets a nonzero attribution.
- Implementation invariance: two functionally equivalent networks (same input-output behaviour) get the same attributions.
Compared to attention: Jain and Wallace [6] showed that attention weights do not satisfy completeness or sensitivity and can be adversarially modified while preserving predictions. IG is a more faithful attribution method for transformer models.
Comparison of attribution methods
| Method | Granularity | Faithfulness | Compute | Applicable to | Output |
|---|---|---|---|---|---|
| Vanilla gradients | Feature-level | Low (local only, no completeness) | One backward pass | Any differentiable model | Gradient map |
| Integrated Gradients | Feature-level | High (completeness, sensitivity axioms) | O(m) backward passes | Any differentiable model | Attribution map summing to output diff |
| SHAP (KernelSHAP) | Feature-level | High (Shapley axioms: efficiency, symmetry, dummy, additivity) | O(2^d) samples; fast in practice with TreeSHAP | Any model (model-agnostic) | Additive feature importances summing to output |
| LIME | Feature-level (superpixel / token) | Medium (local approximation may be poor) | O(N) model evaluations | Any model (model-agnostic) | Linear model coefficients |
| Attention weights | Token-level | Low (not faithful per Jain & Wallace 2019) | Free (already computed) | Transformer models only | Weight distribution over input tokens |
Differential privacy
Differential privacy (DP) provides a mathematical guarantee that an individual’s data cannot be significantly inferred from a model or statistic, even by a computationally unbounded adversary.
Formal definition. A randomised mechanism is -DP if for all adjacent datasets (differing in one individual’s record) and all output subsets :
The parameter (epsilon) is the privacy budget: smaller means stronger privacy. is a small failure probability (typically ). The constraint says: the output distribution is nearly the same whether or not any single individual’s data is included.
DP-SGD [7] achieves differential privacy during neural network training by: (1) gradient clipping: clip each per-sample gradient to norm at most ; (2) Gaussian noise addition: add noise to the sum of clipped gradients before the weight update. The privacy cost accumulates with training steps and is tracked with the moments accountant.
Privacy-accuracy trade-off. Adding noise degrades model accuracy. The optimal noise level depends on the dataset size , the sensitivity (clip norm ), and the number of training steps . For large the noise is small relative to the gradient signal; DP-SGD at loses only 1-2% accuracy on CIFAR-10. For small (medical datasets with thousands of records) the trade-off is severe.
Federated learning
Federated learning [8] trains a model across multiple devices or organisations without centralising the raw data. The canonical algorithm is FedAvg:
- A central server sends the current model weights to a subset of clients.
- Each client trains locally for epochs on its private data, producing updated weights .
- The server aggregates: , where is client ‘s dataset size and .
- Repeat.
Raw data never leaves the client. This addresses both privacy regulations (GDPR) and practical constraints (edge devices that cannot upload data). Combining federated learning with DP-SGD provides formal privacy guarantees even against a malicious server.
Challenges: communication cost (sending model weights to thousands of clients), statistical heterogeneity (client data is non-iid), and system heterogeneity (devices have different compute and battery constraints).
Pitfalls
Demographic parity sounds intuitive but can require the model to make less accurate predictions for one group to equalise prediction rates. If Group A has a 5% positive rate and Group B has a 20% positive rate in the data, enforcing demographic parity forces the model to either over-predict for Group A or under-predict for Group B. In a loan application setting, this directly harms accuracy and may not actually benefit the disadvantaged group. Always state explicitly which fairness criterion you are optimising and why it is appropriate for the specific decision context.
A common mistake is to visualise attention weights and conclude “the model is looking at these words when making its prediction.” Jain and Wallace [6] showed that attention distributions can be adversarially perturbed without changing model predictions, and that different attention distributions produce the same output. Attention reflects what the model attends to, not what it uses. Use Integrated Gradients or SHAP for faithful attribution in transformer models.
For tree-based models (XGBoost, LightGBM, sklearn RandomForest), TreeSHAP computes exact Shapley values in polynomial time and is production-fast. For a 100-tree XGBoost model with depth 6, TreeSHAP computes 10,000 SHAP values in under 1 second. Use this rather than KernelSHAP (which is slow and approximate) for feature attribution at inference time.
Pop quiz
- 1. The fairness impossibility theorem states that:
- 2. The Shapley value efficiency axiom states that:
- 3. Integrated Gradients satisfies completeness, meaning:
- 4. In (epsilon, delta)-differential privacy, smaller epsilon means:
Interview Q&A
Sketch the fairness impossibility theorem. When can all three criteria hold simultaneously?onsite
Consider a binary classifier predicting recidivism (positive = will reoffend) for two groups with base rates . Define:
- PPV (precision):
- FPR:
- FNR:
From Bayes: .
If FPR and FNR are equal across groups (equalized odds), but , plugging into the Bayes equation shows .
So equalized odds implies unequal PPV (predictive parity violation). Conversely, equal PPV across groups (calibration) combined with equal FPR implies unequal FNR when base rates differ.
When can all hold? Only when (equal base rates) or when the classifier is perfect (FPR = FNR = 0 for both groups, so PPV = 1 trivially).
Implication: the choice of fairness criterion is a value judgment. Equal opportunity favours Group 1 (qualified applicants in each group have equal chance of acceptance). Demographic parity favours equal acceptance rates. Calibration favours accuracy within each group. Each criterion privileges different stakeholders.
Derive the Shapley value formula and explain why it is the unique fair attribution satisfying the four axioms.staff
The Shapley value allocates the total “payout” of a coalition game among players. For ML, the “game” is predicting and each “player” is an input feature. The coalition value is the expected prediction when only features are known.
The weight is the probability that coalition forms before feature joins, under a uniformly random ordering. The value is feature ‘s marginal contribution given .
Uniqueness. Shapley proved that the four axioms (efficiency, symmetry, dummy, additivity) uniquely determine this formula. Proof sketch by efficiency + linearity: efficiency forces the sum to equal . Symmetry forces interchangeable features to get equal shares. Dummy forces non-contributing features to get zero. Additivity forces the attribution to decompose across additive model components. Together these four constraints have exactly one solution, which is the Shapley formula.
For an interview follow-up. TreeSHAP computes exact Shapley values for tree ensembles in by recursive tree traversal. KernelSHAP approximates them for any model by sampling feature coalitions and fitting a weighted linear regression. Both are guaranteed to satisfy all four Shapley axioms.
Interactive Demo
Fairness Metrics Explorer
Explore how demographic parity, equal opportunity, and predictive parity relate - and why they cannot all be satisfied simultaneously when base rates differ.
References
References
- Chouldechova, A. (2017). Fair Prediction with Disparate Impact: A Study of Bias in Recidivism Prediction Instruments. Big Data. arXiv:1610.07524
- Kleinberg, J., Mullainathan, S., and Raghavan, M. (2016). Inherent Trade-Offs in the Fair Determination of Risk Scores. ITCS 2017. arXiv:1609.05807
- Lundberg, S. M., and Lee, S.-I. (2017). A Unified Approach to Interpreting Model Predictions. NeurIPS 2017. arXiv:1705.07874
- Ribeiro, M. T., Singh, S., and Guestrin, C. (2016). "Why Should I Trust You?": Explaining the Predictions of Any Classifier. KDD 2016. arXiv:1602.04938
- Sundararajan, M., Taly, A., and Yan, Q. (2017). Axiomatic Attribution for Deep Networks. ICML 2017. arXiv:1703.01365
- Jain, S., and Wallace, B. C. (2019). Attention is not Explanation. NAACL 2019. arXiv:1902.10186
- Abadi, M., Chu, A., Goodfellow, I., McMahan, H. B., Mironov, I., Talwar, K., and Zhang, L. (2016). Deep Learning with Differential Privacy. CCS 2016. arXiv:1607.00133
- McMahan, H. B., Moore, E., Ramage, D., Hampson, S., and y Arcas, B. A. (2017). Communication-Efficient Learning of Deep Networks from Decentralized Data. AISTATS 2017. arXiv:1602.05629