||Privacy-preserving federated cancer detection across 6 African hospitals where patient data never leaves the institution.
# Pan-African Federated Cancer Detection Network
A federated learning system that trains a shared breast cancer detection model across 6 hospitals in 6 countries, without a single patient record ever leaving any hospital.
## Problem
12 hospitals across 6 African countries want to train a shared AI model to detect breast cancer. But patient data cannot leave each country due to privacy laws (NDPR Nigeria, POPIA South Africa). Centralizing data is legally impossible.
## Quick Start
```bash
pip install -r requirements.txt
# Simulate 20 rounds of federated learning across 6 hospitals
python run_federation.py
```
## Architecture
```
Hospital A (Lagos) ┐
Hospital B (Nairobi) │ Local training only
Hospital C (Cape Town) ├→ Weight updates (DP-noised) → Aggregation Server
Hospital D (Accra) │ ↓
Hospital E (Kampala) │ Global Model (shared back)
Hospital F (Addis) ┘
```
**Patient data never leaves the hospital.** Only model weights travel.
## Components
### Federated Server (`src/federation/server.py`)
- FedAvg: weighted average by number of local samples
- Configurable: min clients per round, fraction participating
- Flower (flwr) strategy or mock simulation mode
- Tracks per-round loss and accuracy across all hospitals
### Hospital Client (`src/federation/client.py`)
- Loads local patient data → trains → shares ONLY weights
- Compatible with Flower's NumPyClient interface
- Supports PyTorch or mock training
### Differential Privacy (`src/privacy/differential_privacy.py`)
- **Gradient clipping**: bounds L2 norm of each update
- **Gaussian noise**: calibrated to (ε, δ)-DP guarantee
- **Secure aggregation**: server computes average without seeing individual updates
- Default: ε=1.0, δ=1e-5 (strong privacy guarantee)
## Privacy Guarantee
| Config | ε | Noise σ | Weight Error |
|--------|---|---------|-------------|
| High privacy | 0.5 | 2.16 | High |
| Standard | 1.0 | 1.08 | Medi …