This project demonstrates how to use Federated Learning (FL) to train a privacy-preserving machine learning model on healthcare data (diabetes prediction), using the Flower framework and PyTorch.
Instead of sending raw patient data to a centralized server, this project enables multiple clients to collaboratively train a model without sharing their data, preserving privacy and data security.
Federated Learning is a machine learning approach where:
- Multiple clients (e.g., hospitals, devices) train a model locally on their private data.
- Only model updates (weights) are shared with a central server.
- The server aggregates these updates to improve a global model.
- Raw data never leaves the clients, ensuring data privacy.
Federated Learning is ideal for sensitive domains like:
- Healthcare
- Finance
- Mobile devices
Feature | Details |
---|---|
Task | Binary classification: Predict whether a person has diabetes |
Frameworks | PyTorch + Flower |
Privacy | Raw healthcare data stays on each client |
Model | Feedforward Neural Network (3-layer) |
Training | Federated with 2 simulated clients, 10 rounds |
Evaluation | Accuracy is aggregated from all clients |
Visualization | Global accuracy vs. training rounds plotted after training |
We use the Pima Indians Diabetes Dataset (diabetes.csv
), which contains medical diagnostic data for female patients.
- Kaggle Dataset Link
- Features:
Glucose
,BloodPressure
,BMI
,Age
, etc. - Target:
Outcome
(0 = No diabetes, 1 = Diabetes)
.
├── model.py # PyTorch model definition
├── utils.py # Data loading & client data splitting
├── server.py # Flower server with accuracy plotting
├── client.py # Flower client with local training
├── diabetes.csv # Dataset file
├── federated\_accuracy\_plot.png # Generated after training
└── README.md # You are here
Make sure you have
diabetes.csv
in your project folder.
pip install flwr torch scikit-learn pandas matplotlib
python server.py
python client.py
# Enter: 0
python client.py
# Enter: 1
Training will run for 10 federated rounds. A graph showing global accuracy vs. round will be displayed after completion and saved as
federated_accuracy_plot.png
.
Traditional ML | Federated Learning |
---|---|
Centralized data storage | Data remains on client devices |
Higher risk of data leaks | Improved privacy and compliance |
Requires large central dataset | Enables collaboration across institutions |
Muhammad Asim Hanif