Module 7 — Federated & Privacy-Preserving ML
Same theory-first structure as Modules 1–6: for every technique below, what it is, why it exists — the specific problem it was invented to solve — what else you could use instead, and a real financial example. Every module so far has assumed RR Finance's training data lives in one place. Module 7 removes that assumption: what if the data can never actually be centralized at all?
Recap — what RR Finance already has
Module 7 is not a fresh start. Here's exactly what it inherits before removing the centralized-data assumption.
A validated logistic-regression baseline and a deeper ANN, both trained on one centralized CSV — the assumption this module removes.
Data poisoning and an Isolation Forest defence — the row-level version of the aggregation-layer attack this module introduces.
SHAP, LIME, counterfactuals, and a real age-fairness audit — all computed on a centrally-trained model. This module asks whether that audit still holds once training changes.
Why the data can't move
Real cross-institution credit modelling runs into a wall no algorithm can fix by being smarter: the data is not allowed to leave.
The legal/commercial reality
Data residency rules, privacy law, and competitive confidentiality between lending institutions mean raw applicant records often cannot be centralized, no matter how much better the resulting model would be.
The federated answer
Move the MODEL to the data instead of the data to the model — train locally at each institution, share only the resulting weight updates.
Why new attack surfaces follow
A server that trusts every institution's returned update equally, and a model whose weights alone might still leak information about individual applicants, are two NEW risks this module confronts directly.
Why Federated Learning
Moving the model to the data, instead of the data to the model.
Federated Learning trains one shared model across data that lives at multiple separate locations ("clients" or, for RR Finance, partner institutions), without any of them sending their raw data anywhere else. Each institution trains locally; only the resulting model updates ever travel.
✓ Use it when
- Data residency law, competitive confidentiality, or privacy regulation prevents centralizing training data across institutions
- Each participant has enough local data to contribute a meaningful, non-trivial local training update
✗ Reach for something else when
- Centralizing the data is actually permitted and simpler — federation adds real complexity (communication rounds, aggregation, new attack surfaces) that a centralized pipeline (Modules 1–6) simply doesn't need
Federated Averaging (FedAvg)
The foundational algorithm: train locally, average globally, repeat.
FedAvg is the core federated learning algorithm: each communication round, every client trains the current global model on its own local data for a few epochs, then the server collects every client's resulting weights and averages them to produce the next global model.
✓ What the notebook demonstrates
- A working FedAvg loop across 5 simulated RR Finance institutions, reaching test accuracy comparable to — in this run, even slightly ahead of — a centralized benchmark trained on all the same data in one place
✗ What FedAvg does NOT guarantee on its own
- Privacy (Concept 4 adds that) or robustness to a malicious participant (Concepts 5–6 address that) — plain FedAvg only solves the "don't centralize the data" problem
The Non-IID Challenge
FedAvg's convenient assumption, and what breaks when it's false.
FedAvg's simple averaging works best when every client's local data looks statistically similar to every other client's — an IID (independent and identically distributed) assumption. Real institutions rarely satisfy this: a regional branch, or a partner lender specializing in one credit tier, has data that looks systematically DIFFERENT from another institution's.
✓ What the notebook demonstrates
- A REAL non-IID split — institutions partitioned by sorted
credit_score, so each one genuinely specializes in one tier — measurably underperforming the IID split from Concept 2
✗ An honest limitation, stated plainly
- The measured gap here is modest, not catastrophic, because 5 institutions with mild specialization is a small-scale, low-heterogeneity example — real deployments with more clients and more extreme specialization see substantially larger degradation
Differential Privacy (DP-SGD)
A mathematical guarantee, not just a best-effort defence, on what one applicant's data could reveal.
Differential Privacy bounds exactly how much any single training example could have changed the trained model — quantified by a privacy budget ε (epsilon). DP-SGD achieves this during neural network training by clipping each example's gradient contribution and adding calibrated random noise before every optimizer step.
opacus library.
✓ Use it when
- Federation alone (Concept 2) keeps raw data local, but the TRAINED MODEL itself must also carry a provable guarantee against leaking whether any specific applicant was in the training set
✗ Watch out for
- Privacy is not free — the notebook measures a REAL accuracy cost that grows as ε shrinks (stronger privacy); on this small, 800-row dataset the effect is somewhat noisy run-to-run, since DP's injected noise is more visible relative to a small dataset's signal
1e-5 in the notebook) by convention.Model Poisoning at the Aggregation Layer
Module 1 poisoned the data. This poisons the UPDATE instead.
Module 1 demonstrated data poisoning — corrupting training rows before centralized training. Federated learning opens a related but distinct attack surface: one participating institution can send a corrupted or malicious MODEL UPDATE instead of real locally-trained weights — a Byzantine fault, borrowing the term from distributed-systems literature for a participant that can fail or misbehave in an arbitrary way.
✓ What the notebook demonstrates
- A real, working attack: one institution (out of 5) returns a massively scaled, sign-flipped update instead of its real weights, and naive mean aggregation (Concept 2) has no mechanism to notice or resist it — a measured accuracy drop, not a hypothetical one
✗ What this is NOT
- A claim that any real institution WOULD do this — the point is that the server's aggregation rule alone has to be robust to the possibility, since it cannot verify what happened inside any institution's own training loop
Byzantine-Robust Aggregation
Fixing the aggregation rule itself, without ever inspecting any client's data.
Two classic robust aggregation rules replace the simple mean: coordinate-wise median (the middle value per parameter across all clients) and trimmed mean (discard the most extreme values per parameter before averaging the rest). Both limit how much a single outlier update can influence the aggregated result.
✓ What the notebook demonstrates
- Both rules substantially recover the accuracy Concept 5's attack destroyed, using ONLY the returned weights — no institution's raw data or training process is ever inspected
✗ An honest limitation, stated plainly
- Neither rule defends against a COLLUDING MAJORITY of malicious institutions — median and trimmed mean both assume malicious participants are outnumbered, a real constraint worth naming rather than implying these defences are unconditional
Fairness Under Federation
Module 6's audit was tied to a centralized model. Does it still hold?
Module 6 measured demographic-parity and equalized-odds gaps by age group on a CENTRALLY trained classifier. This lesson re-runs the EXACT same audit on the federated model from Concept 2, to check whether federation itself changes that fairness profile.
✓ What the notebook demonstrates
- A real, measured comparison: the federated model's demographic-parity and equalized-odds gaps genuinely differ from the centralized model's — moving in different directions on the two metrics, not uniformly better or worse
✗ What NOT to conclude
- This is a single comparison on one dataset and one architecture — it is NOT evidence that federation always helps or always hurts fairness; the finding is that it CHANGES, which is itself the reason to re-audit rather than assume
Module 7 hand-off
The notebook implements a real FedAvg loop across 5 simulated institutions, measures the real accuracy cost of realistic non-IID data, trains the same architecture under real DP-SGD (via opacus) across five different privacy budgets, demonstrates a real model-poisoning attack against naive aggregation, defends against it with two real Byzantine-robust aggregation rules, and re-runs Module 6's fairness audit on the federated model to show it must be re-measured, not assumed -- with a metrics summary saved as an artifact for the next module.