A library for federated learning and personalized federated learning with Generalized Linear Models
Project description
# Federated GLM
[](https://pypi.org/project/federated-glm/)
[](LICENSE)
[](https://pypi.org/project/federated-glm/)
**Federated GLM** is a Python package for simulating **federated learning** with **generalized linear models (GLMs)**. It supports Gaussian, Binomial, and Poisson families, and allows flexible experimentation with elastic net regularization, client data partitioning, and convergence diagnostics.
---
## ๐ง Features
- Federated learning framework with `average` or `weighted` aggregation
- Supports **Gaussian**, **Binomial**, and **Poisson** GLM families
- Elastic Net, Lasso, and Ridge regularization (proximal updates)
- Utilities for synthetic data generation and partitioning across clients
- Model evaluation with Rยฒ, RMSE, accuracy, Poisson deviance, etc.
- Examples for comparing centralized and federated learning
- Simple API and complete test coverage
---
## ๐ฆ Installation
```bash
pip install git+https://github.com/mhmdamini/federated-glm.git
To install with development or example dependencies:
pip install "federated-glm[dev]"
pip install "federated-glm[examples]"
๐ Quick Start
Hereโs a minimal example using Gaussian regression:
from federated_glm import PersonalizedFederatedGLM, FederatedLearningManager, DataGenerator, ModelEvaluator
# Generate synthetic data
X, y, family = DataGenerator.generate_glm_data("gaussian", n=200, p=3)
# Split train/test
X_train, X_test = X[:150], X[150:]
y_train, y_test = y[:150], y[150:]
# Partition data across clients
client_data = DataGenerator.partition_data(X_train, y_train, n_clients=3)
# Train a federated model
manager = FederatedLearningManager()
manager.fit(client_data, family, n_rounds=10)
# Predict and evaluate
y_pred = manager.predict(X_test, family)
metrics = ModelEvaluator.evaluate(y_test, y_pred, "gaussian")
print("Rยฒ Score:", metrics["r2_score"])
print("RMSE:", metrics["rmse"])
For personalized federated learning, it will be:
pfed = PersonalizedFederatedGLM(method='pfedme')
pfed.fit(client_data, family, n_rounds=20)
Where method can be 'pfedme', 'perfedavg', and 'local_adaptation'.
๐ Project Structure
federated-glm/
โโโ federated_glm/ # Core package
โ โโโ core.py # Federated GLM base class with proximal optimization
โ โโโ federation.py # Federated learning manager
โ โโโ evaluation.py # Model evaluation metrics
โ โโโ utils.py # Data generation & partitioning utilities
โ โโโ __init__.py
โ โโโ personalized.py. # personalized federated learning
โโโ examples/ # Usage examples
โ โโโ basic_example.py
โ โโโ simple_example.py
โ โโโ personalized_example.py
โโโ tests/ # Unit and integration tests
โ โโโ test_basic.py
โโโ requirements.txt
โโโ setup.py
โโโ LICENSE
โโโ README.md
๐ Examples
Run the full demo script:
python examples/basic_example.py
This includes:
- Federated and personalized federated learning vs centralized performance comparison
- Convergence visualization
- Comparison of regularization strategies (ordinary, lasso, elastic net)
โ Supported GLM Families
| Family | Link Function | Use Case |
|---|---|---|
| Gaussian | Identity | Regression on continuous targets |
| Binomial | Logit | Binary classification |
| Poisson | Log | Count data modeling |
๐งช Testing
To run tests:
pip install "federated-glm[dev]"
pytest tests/
๐ Documentation
Documentation is available in the GitHub README.
๐ License
This project is licensed under the MIT License.
๐จโ๐ป Author
Mohammad Amini Ph.D. Student at University of Florida m.amini@ufl.edu GitHub: @mhmdamini
๐ Acknowledgements
- Built on StatsModels and Scikit-learn
- Inspired by research in federated learning, GLMs, and distributed optimization
๐ฌ Contributing & Issues
Please open issues or submit pull requests via the GitHub repository.
We welcome contributions to:
- Support more GLM families (e.g., Negative Binomial, Gamma)
- Extend to real-world datasets
- Add differential privacy or secure aggregation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file federated_glm-0.2.0.tar.gz.
File metadata
- Download URL: federated_glm-0.2.0.tar.gz
- Upload date:
- Size: 13.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3beb8c97dabde7633b9e2989f871047f0d623ed47d5efff6f669a308b3d73b8e
|
|
| MD5 |
875ea7cef723f483d19459fd9a241d6c
|
|
| BLAKE2b-256 |
9fa0bd534727cf94f761e1be818cca57c0fae0e0b8aef2a0ed1e71f26abd503e
|
File details
Details for the file federated_glm-0.2.0-py3-none-any.whl.
File metadata
- Download URL: federated_glm-0.2.0-py3-none-any.whl
- Upload date:
- Size: 11.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75620a747da54fef910e38b7402b608c874673e90a3ca00c4cfd56bc73a8e51f
|
|
| MD5 |
c2b8d1bb599a6c067def73e620182681
|
|
| BLAKE2b-256 |
7c32b4df39d1ac6f1a5fc6f3889f13d7e8a0f83565d296fc2f944b4ae875f387
|