Skip to main content

A library for federated learning with Generalized Linear Models

Project description

# 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 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"])

๐Ÿ“ 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
โ”œโ”€โ”€ examples/                  # Usage examples
โ”‚   โ””โ”€โ”€ basic_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 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

federated_glm-0.1.0.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

federated_glm-0.1.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file federated_glm-0.1.0.tar.gz.

File metadata

  • Download URL: federated_glm-0.1.0.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.18

File hashes

Hashes for federated_glm-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0888d94168ffc71ba8b709f358d99b0f7b430ea7efae44b35fa2b0abfb599004
MD5 2137da2943fda7921fa5cc5d988ec4ff
BLAKE2b-256 6c69106febfbd2c86e560f72e3df654978a83585c1ebc0014576e6ffeca37d34

See more details on using hashes here.

File details

Details for the file federated_glm-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: federated_glm-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.18

File hashes

Hashes for federated_glm-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7a2335a0ea85592981b6e23de0e27fbf89df560d4ad2b61f0529059e2667fa3e
MD5 6705a5e84e9bf7ab07d7d3a29775a345
BLAKE2b-256 fc6d6ede4c91d929f29ccde8f0d2e8e55253c0482e08039c083156817188ea41

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page