federated-glm


Namefederated-glm JSON
Version 0.2.0 PyPI version JSON
download
home_pagehttps://github.com/mhmdamini/federated-glm
SummaryA library for federated learning and personalized federated learning with Generalized Linear Models
upload_time2025-07-13 10:58:37
maintainerNone
docs_urlNone
authorMohammad Amini
requires_python>=3.8
licenseNone
keywords federated-learning glm machine-learning statistics personalization
VCS
bugtrack_url
requirements numpy scipy statsmodels scikit-learn pandas
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ````markdown
# 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:

```bash
pip install "federated-glm[dev]"
pip install "federated-glm[examples]"
```

---

## πŸ›  Quick Start

Here’s a minimal example using Gaussian regression:

```python
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:

```python
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:

```bash
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:

```bash
pip install "federated-glm[dev]"
pytest tests/
```

---

## πŸ“š Documentation

Documentation is available in the [GitHub README](https://github.com/mhmdamini/federated-glm#readme).

---

## πŸ“œ License

This project is licensed under the [MIT License](LICENSE).

---

## πŸ‘¨β€πŸ’» Author

**Mohammad Amini**
Ph.D. Student at University of Florida
[m.amini@ufl.edu](mailto:m.amini@ufl.edu)
[GitHub: @mhmdamini](https://github.com/mhmdamini)

---

## πŸ™Œ Acknowledgements

* Built on [StatsModels](https://www.statsmodels.org/) and [Scikit-learn](https://scikit-learn.org/)
* Inspired by research in federated learning, GLMs, and distributed optimization

---

## πŸ“¬ Contributing & Issues

Please open issues or submit pull requests via the [GitHub repository](https://github.com/mhmdamini/federated-glm).

We welcome contributions to:

* Support more GLM families (e.g., Negative Binomial, Gamma)
* Extend to real-world datasets
* Add differential privacy or secure aggregation

---

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mhmdamini/federated-glm",
    "name": "federated-glm",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "federated-learning, glm, machine-learning, statistics, personalization",
    "author": "Mohammad Amini",
    "author_email": "m.amini@ufl.edu",
    "download_url": "https://files.pythonhosted.org/packages/9f/a0/bd534727cf94f761e1be818cca57c0fae0e0b8aef2a0ed1e71f26abd503e/federated_glm-0.2.0.tar.gz",
    "platform": null,
    "description": "````markdown\n# Federated GLM\n\n[![PyPI - Version](https://img.shields.io/pypi/v/federated-glm.svg)](https://pypi.org/project/federated-glm/)\n[![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)\n[![Python Versions](https://img.shields.io/pypi/pyversions/federated-glm.svg)](https://pypi.org/project/federated-glm/)\n\n**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.\n\n---\n\n## \ud83d\udd27 Features\n\n- Federated learning framework with `average` or `weighted` aggregation\n- Supports **Gaussian**, **Binomial**, and **Poisson** GLM families\n- Elastic Net, Lasso, and Ridge regularization (proximal updates)\n- Utilities for synthetic data generation and partitioning across clients\n- Model evaluation with R\u00b2, RMSE, accuracy, Poisson deviance, etc.\n- Examples for comparing centralized and federated learning\n- Simple API and complete test coverage\n\n---\n\n## \ud83d\udce6 Installation\n\n```bash\npip install git+https://github.com/mhmdamini/federated-glm.git\n````\n\nTo install with development or example dependencies:\n\n```bash\npip install \"federated-glm[dev]\"\npip install \"federated-glm[examples]\"\n```\n\n---\n\n## \ud83d\udee0 Quick Start\n\nHere\u2019s a minimal example using Gaussian regression:\n\n```python\nfrom federated_glm import PersonalizedFederatedGLM, FederatedLearningManager, DataGenerator, ModelEvaluator\n\n# Generate synthetic data\nX, y, family = DataGenerator.generate_glm_data(\"gaussian\", n=200, p=3)\n\n# Split train/test\nX_train, X_test = X[:150], X[150:]\ny_train, y_test = y[:150], y[150:]\n\n# Partition data across clients\nclient_data = DataGenerator.partition_data(X_train, y_train, n_clients=3)\n\n# Train a federated model\nmanager = FederatedLearningManager()\nmanager.fit(client_data, family, n_rounds=10)\n\n# Predict and evaluate\ny_pred = manager.predict(X_test, family)\nmetrics = ModelEvaluator.evaluate(y_test, y_pred, \"gaussian\")\n\nprint(\"R\u00b2 Score:\", metrics[\"r2_score\"])\nprint(\"RMSE:\", metrics[\"rmse\"])\n\n```\n\nFor personalized federated learning, it will be:\n\n```python\npfed = PersonalizedFederatedGLM(method='pfedme')\npfed.fit(client_data, family, n_rounds=20)\n```\nWhere method can be 'pfedme', 'perfedavg', and 'local_adaptation'.\n\n---\n\n## \ud83d\udcc1 Project Structure\n\n```\nfederated-glm/\n\u251c\u2500\u2500 federated_glm/             # Core package\n\u2502   \u251c\u2500\u2500 core.py                # Federated GLM base class with proximal optimization\n\u2502   \u251c\u2500\u2500 federation.py          # Federated learning manager\n\u2502   \u251c\u2500\u2500 evaluation.py          # Model evaluation metrics\n\u2502   \u251c\u2500\u2500 utils.py               # Data generation & partitioning utilities\n\u2502   \u2514\u2500\u2500 __init__.py\n\u2502   \u2514\u2500\u2500 personalized.py.       # personalized federated learning\n\u251c\u2500\u2500 examples/                  # Usage examples\n\u2502   \u2514\u2500\u2500 basic_example.py\n\u2502   \u2514\u2500\u2500 simple_example.py\n\u2502   \u2514\u2500\u2500 personalized_example.py\n\u251c\u2500\u2500 tests/                     # Unit and integration tests\n\u2502   \u2514\u2500\u2500 test_basic.py\n\u251c\u2500\u2500 requirements.txt\n\u251c\u2500\u2500 setup.py\n\u251c\u2500\u2500 LICENSE\n\u2514\u2500\u2500 README.md\n```\n\n---\n\n## \ud83d\udcc8 Examples\n\nRun the full demo script:\n\n```bash\npython examples/basic_example.py\n```\n\nThis includes:\n\n* Federated and personalized federated learning vs centralized performance comparison\n* Convergence visualization\n* Comparison of regularization strategies (ordinary, lasso, elastic net)\n\n---\n\n## \u2705 Supported GLM Families\n\n| Family   | Link Function | Use Case                         |\n| -------- | ------------- | -------------------------------- |\n| Gaussian | Identity      | Regression on continuous targets |\n| Binomial | Logit         | Binary classification            |\n| Poisson  | Log           | Count data modeling              |\n\n---\n\n## \ud83e\uddea Testing\n\nTo run tests:\n\n```bash\npip install \"federated-glm[dev]\"\npytest tests/\n```\n\n---\n\n## \ud83d\udcda Documentation\n\nDocumentation is available in the [GitHub README](https://github.com/mhmdamini/federated-glm#readme).\n\n---\n\n## \ud83d\udcdc License\n\nThis project is licensed under the [MIT License](LICENSE).\n\n---\n\n## \ud83d\udc68\u200d\ud83d\udcbb Author\n\n**Mohammad Amini**\nPh.D. Student at University of Florida\n[m.amini@ufl.edu](mailto:m.amini@ufl.edu)\n[GitHub: @mhmdamini](https://github.com/mhmdamini)\n\n---\n\n## \ud83d\ude4c Acknowledgements\n\n* Built on [StatsModels](https://www.statsmodels.org/) and [Scikit-learn](https://scikit-learn.org/)\n* Inspired by research in federated learning, GLMs, and distributed optimization\n\n---\n\n## \ud83d\udcec Contributing & Issues\n\nPlease open issues or submit pull requests via the [GitHub repository](https://github.com/mhmdamini/federated-glm).\n\nWe welcome contributions to:\n\n* Support more GLM families (e.g., Negative Binomial, Gamma)\n* Extend to real-world datasets\n* Add differential privacy or secure aggregation\n\n---\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A library for federated learning and personalized federated learning with Generalized Linear Models",
    "version": "0.2.0",
    "project_urls": {
        "Bug Reports": "https://github.com/mhmdamini/federated-glm/issues",
        "Documentation": "https://github.com/mhmdamini/federated-glm#readme",
        "Homepage": "https://github.com/mhmdamini/federated-glm",
        "Source": "https://github.com/mhmdamini/federated-glm"
    },
    "split_keywords": [
        "federated-learning",
        " glm",
        " machine-learning",
        " statistics",
        " personalization"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "7c32b4df39d1ac6f1a5fc6f3889f13d7e8a0f83565d296fc2f944b4ae875f387",
                "md5": "c2b8d1bb599a6c067def73e620182681",
                "sha256": "75620a747da54fef910e38b7402b608c874673e90a3ca00c4cfd56bc73a8e51f"
            },
            "downloads": -1,
            "filename": "federated_glm-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c2b8d1bb599a6c067def73e620182681",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 11085,
            "upload_time": "2025-07-13T10:58:36",
            "upload_time_iso_8601": "2025-07-13T10:58:36.185044Z",
            "url": "https://files.pythonhosted.org/packages/7c/32/b4df39d1ac6f1a5fc6f3889f13d7e8a0f83565d296fc2f944b4ae875f387/federated_glm-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "9fa0bd534727cf94f761e1be818cca57c0fae0e0b8aef2a0ed1e71f26abd503e",
                "md5": "875ea7cef723f483d19459fd9a241d6c",
                "sha256": "3beb8c97dabde7633b9e2989f871047f0d623ed47d5efff6f669a308b3d73b8e"
            },
            "downloads": -1,
            "filename": "federated_glm-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "875ea7cef723f483d19459fd9a241d6c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 13324,
            "upload_time": "2025-07-13T10:58:37",
            "upload_time_iso_8601": "2025-07-13T10:58:37.158310Z",
            "url": "https://files.pythonhosted.org/packages/9f/a0/bd534727cf94f761e1be818cca57c0fae0e0b8aef2a0ed1e71f26abd503e/federated_glm-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-13 10:58:37",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mhmdamini",
    "github_project": "federated-glm",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "numpy",
            "specs": [
                [
                    ">=",
                    "1.21.0"
                ]
            ]
        },
        {
            "name": "scipy",
            "specs": [
                [
                    ">=",
                    "1.7.0"
                ]
            ]
        },
        {
            "name": "statsmodels",
            "specs": [
                [
                    ">=",
                    "0.13.0"
                ]
            ]
        },
        {
            "name": "scikit-learn",
            "specs": [
                [
                    ">=",
                    "1.0.0"
                ]
            ]
        },
        {
            "name": "pandas",
            "specs": [
                [
                    ">=",
                    "1.3.0"
                ]
            ]
        }
    ],
    "lcname": "federated-glm"
}
        
Elapsed time: 0.62933s