Skip to main content
# Federated GLM

[![PyPI - Version](https://img.shields.io/pypi/v/federated-glm.svg)](https://pypi.org/project/federated-glm/)
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
[![Python Versions](https://img.shields.io/pypi/pyversions/federated-glm.svg)](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

Metadata

Release files for federated-glm 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for federated-glm 0.2.0
File Size Uploaded Provenance Actions
federated_glm-0.2.0.tar.gz 13.3 kB Without provenance Details for federated_glm-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for federated-glm 0.2.0
File Interpreter ABI Platform Actions
federated_glm-0.2.0-py3-none-any.whl Python 3 none any Details for federated_glm-0.2.0-py3-none-any.whl

Total release size: 24.4 kB

Release files / federated_glm-0.2.0.tar.gz

Download URL federated_glm-0.2.0.tar.gz
Size 13.3 kB
Tags Source
SHA-256 checksum
How to use checksums
3beb8c97dabde7633b9e2989f871047f0d623ed47d5efff6f669a308b3d73b8e
BLAKE2b-256 checksum
How to use checksums
9fa0bd534727cf94f761e1be818cca57c0fae0e0b8aef2a0ed1e71f26abd503e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.18

Release files / federated_glm-0.2.0-py3-none-any.whl

Download URL federated_glm-0.2.0-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
75620a747da54fef910e38b7402b608c874673e90a3ca00c4cfd56bc73a8e51f
BLAKE2b-256 checksum
How to use checksums
7c32b4df39d1ac6f1a5fc6f3889f13d7e8a0f83565d296fc2f944b4ae875f387
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.18

Security for federated-glm 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page