{"id":13487513,"url":"https://github.com/IBM/differential-privacy-library","last_synced_at":"2025-03-27T22:31:26.253Z","repository":{"id":34979825,"uuid":"192547145","full_name":"IBM/differential-privacy-library","owner":"IBM","description":"Diffprivlib: The IBM Differential Privacy Library","archived":false,"fork":false,"pushed_at":"2024-10-10T12:40:54.000Z","size":2221,"stargazers_count":820,"open_issues_count":5,"forks_count":197,"subscribers_count":33,"default_branch":"main","last_synced_at":"2024-10-10T12:49:40.393Z","etag":null,"topics":["data-privacy","differential-privacy","machine-learning","python"],"latest_commit_sha":null,"homepage":"https://diffprivlib.readthedocs.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/IBM.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":"code_of_conduct.md","threat_model":null,"audit":null,"citation":"CITATION.bib","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-06-18T13:36:41.000Z","updated_at":"2024-10-10T12:37:11.000Z","dependencies_parsed_at":"2023-01-15T11:23:50.638Z","dependency_job_id":"d2d3a1d1-e0cf-4920-921a-7ef99e364b1e","html_url":"https://github.com/IBM/differential-privacy-library","commit_stats":{"total_commits":549,"total_committers":18,"mean_commits":30.5,"dds":0.4426229508196722,"last_synced_commit":"846adb00a77ae38d7390950499ca03b4942a940c"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IBM%2Fdifferential-privacy-library","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IBM%2Fdifferential-privacy-library/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IBM%2Fdifferential-privacy-library/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IBM%2Fdifferential-privacy-library/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IBM","download_url":"https://codeload.github.com/IBM/differential-privacy-library/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222322034,"owners_count":16966433,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-privacy","differential-privacy","machine-learning","python"],"created_at":"2024-07-31T18:01:00.194Z","updated_at":"2025-03-27T22:31:26.238Z","avatar_url":"https://github.com/IBM.png","language":"Python","funding_links":[],"categories":["Privacy Toolboxes","Differential Privacy Tools","Libraries","ML Code Security","Python","Tools","4. Code","5.4 DP Libraries","Code and Projects","Awesome Privacy Engineering [![Awesome](https://awesome.re/badge.svg)](https://awesome.re)","Securing AI SaaS","Defense \u0026 Security Controls"],"sub_categories":["Interfaces","Privacy","Winetricks","Objective-C Tools, Libraries, and Frameworks","2.4 Differential Privacy in CCS, S\u0026P, NDSS, USENIX, Infocom from 2015-2019 (some of them are from 2020)","Mesh networks","Differential Privacy and Federated Learning","Defensive Tools and Frameworks","Privacy \u0026 Confidential Computing"],"readme":"# Diffprivlib v0.6\n\n[![Python versions](https://img.shields.io/pypi/pyversions/diffprivlib.svg)](https://pypi.org/project/diffprivlib/)\n[![Downloads](https://static.pepy.tech/badge/diffprivlib)](https://pepy.tech/project/diffprivlib)\n[![PyPi version](https://img.shields.io/pypi/v/diffprivlib.svg)](https://pypi.org/project/diffprivlib/)\n[![PyPi status](https://img.shields.io/pypi/status/diffprivlib.svg)](https://pypi.org/project/diffprivlib/)\n[![General tests](https://github.com/IBM/differential-privacy-library/actions/workflows/general.yml/badge.svg)](https://github.com/IBM/differential-privacy-library/actions/workflows/general.yml)\n[![Documentation Status](https://readthedocs.org/projects/diffprivlib/badge/?version=latest)](https://diffprivlib.readthedocs.io/en/latest/?badge=latest)\n[![CodeQL](https://github.com/IBM/differential-privacy-library/actions/workflows/codeql.yml/badge.svg)](https://github.com/IBM/differential-privacy-library/actions/workflows/codeql.yml)\n[![codecov](https://codecov.io/gh/IBM/differential-privacy-library/branch/main/graph/badge.svg)](https://codecov.io/gh/IBM/differential-privacy-library)\n\nDiffprivlib is a general-purpose library for differential privacy (DP). Use diffprivlib if you are looking to:\n\n- Experiment with differential privacy\n- Explore the impact of differential privacy on machine learning and data analytics applications \n- Prototype your own differential privacy algorithms\n\nSince its initial release in 2019, diffprivlib has proven to be an invaluable resource for the DP community, with hundreds of citations, stars, forks and deployments. The library has lowered the barrier to entry for new scientists and engineers working in and learning about DP, spawned new research, and served as a benchmark for new algorithms and libraries.\n\n__Note:__ The public release of diffprivlib is intended for research and education purposes only. Please reach out to us if you are interested in using diffprivlib in a production environment. \n\n## Getting started: [Machine learning with differential privacy in 30 seconds](https://github.com/IBM/differential-privacy-library/blob/main/notebooks/30seconds.ipynb)\nWe're using the [Iris dataset](https://archive.ics.uci.edu/ml/datasets/iris), so let's load it and perform an 80/20 train/test split.\n\n```python\nfrom sklearn import datasets\nfrom sklearn.model_selection import train_test_split\n\ndataset = datasets.load_iris()\nX_train, X_test, y_train, y_test = train_test_split(dataset.data, dataset.target, test_size=0.2)\n```\n\nNow, let's train a differentially private naive Bayes classifier. Our classifier __runs just like an `sklearn` classifier__, so you can get up and running quickly.\n\n`diffprivlib.models.GaussianNB` can be run __without any parameters__, although this will throw a warning (we need to specify the `bounds` parameter to avoid this). The privacy level is controlled by the parameter `epsilon`, which is passed to the classifier at initialisation (e.g. `GaussianNB(epsilon=0.1)`). The default is `epsilon = 1.0`.\n\n```python\nfrom diffprivlib.models import GaussianNB\n\nclf = GaussianNB()\nclf.fit(X_train, y_train)\n```\n\nWe can now classify unseen examples, knowing that the trained model is differentially private and preserves the privacy of the 'individuals' in the training set (flowers are entitled to their privacy too!).\n\n```python\nclf.predict(X_test)\n```\n\nEvery time the model is trained with `.fit()`, a different model is produced due to the randomness of differential privacy. The accuracy will therefore change, even if it's re-trained with the same training data. Try it for yourself to find out!\n\n```python\nprint(\"Test accuracy: %f\" % clf.score(X_test, y_test))\n```\n\nWe can easily evaluate the accuracy of the model for various `epsilon` values and plot it with `matplotlib`.\n\n```python\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nepsilons = np.logspace(-2, 2, 50)\nbounds = ([4.3, 2.0, 1.1, 0.1], [7.9, 4.4, 6.9, 2.5])\naccuracy = list()\n\nfor epsilon in epsilons:\n    clf = GaussianNB(bounds=bounds, epsilon=epsilon)\n    clf.fit(X_train, y_train)\n    \n    accuracy.append(clf.score(X_test, y_test))\n\nplt.semilogx(epsilons, accuracy)\nplt.title(\"Differentially private Naive Bayes accuracy\")\nplt.xlabel(\"epsilon\")\nplt.ylabel(\"Accuracy\")\nplt.show()\n```\n\n![Differentially private naive Bayes](https://github.com/IBM/differential-privacy-library/raw/main/notebooks/30seconds.png)\n\nCongratulations, you've completed your first differentially private machine learning task with the Differential Privacy Library!  Check out more examples in the [notebooks](https://github.com/IBM/differential-privacy-library/blob/main/notebooks/) directory, or [dive straight in](https://github.com/IBM/differential-privacy-library/blob/main/diffprivlib/).\n\n## Contents\n\nDiffprivlib is comprised of four major components:\n1. __Mechanisms:__ These are the building blocks of differential privacy, and are used in all models that implement differential privacy. Mechanisms have little or no default settings, and are intended for use by experts implementing their own models. They can, however, be used outside models for separate investigations, etc.\n1. __Models:__ This module includes machine learning models with differential privacy. Diffprivlib currently has models for clustering, classification, regression, dimensionality reduction and pre-processing.\n1. __Tools:__ Diffprivlib comes with a number of generic tools for differentially private data analysis. This includes differentially private histograms, following the same format as [Numpy's histogram function](https://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram.html).\n1. __Accountant:__ The `BudgetAccountant` class can be used to track privacy budget and calculate total privacy loss using advanced composition techniques. \n\n\n## Setup\n\n### Installation with `pip`\n\nThe library is designed to run with Python 3.\nThe library can be installed from the PyPi repository using `pip` (or `pip3`):\n\n```bash\npip install diffprivlib\n```\n\n### Manual installation\n\nFor the most recent version of the library, either download the source code or clone the repository in your directory of choice:\n\n```bash\ngit clone https://github.com/IBM/differential-privacy-library\n```\n\nTo install `diffprivlib`, do the following in the project folder (alternatively, you can run `python3 -m pip install .`):\n```bash\npip install .\n```\n\nThe library comes with a basic set of unit tests for `pytest`. To check your install, you can run all the unit tests by calling `pytest` in the install folder:\n\n```bash\npytest\n```\n\n## Citing diffprivlib\nIf you use diffprivlib for research, please consider citing the following reference paper:\n```\n@article{diffprivlib,\n  title={Diffprivlib: the {IBM} differential privacy library},\n  author={Holohan, Naoise and Braghin, Stefano and Mac Aonghusa, P{\\'o}l and Levacher, Killian},\n  year={2019},\n  journal = {ArXiv e-prints},\n  archivePrefix = \"arXiv\",\n  volume = {1907.02444 [cs.CR]},\n  primaryClass = \"cs.CR\",\n  month = jul\n}\n```\n\n## References\n\n* Holohan, N., Antonatos, S., Braghin, S. and Mac Aonghusa, P., 2018. [The Bounded Laplace Mechanism in Differential privacy](https://doi.org/10.29012/jpc.715). *Journal of Privacy and Confidentiality 10 (1).*\n* Holohan, N., Braghin, S., Mac Aonghusa, P. and Levacher, K., 2019. [Diffprivlib: the IBM Differential Privacy Library](https://arxiv.org/abs/1907.02444). *ArXiv e-prints 1907.02444 [cs.CR].*\n* Ludwig, H., Baracaldo, N., Thomas, G., Zhou, Y., Anwar, A., Rajamoni, S., Ong, Y., Radhakrishnan, J., Verma, A., Sinn, M. and Purcell, M., 2020. [IBM Federated Learning: an Enterprise Framework White Paper v0.1](https://doi.org/10.48550/arXiv.2007.10987). *ArXiv e-prints 2007.10987 [cs.LG].*\n* Holohan, N. and Braghin, S., 2021. [Secure Random Sampling in Differential Privacy](https://doi.org/10.1007/978-3-030-88428-4_26). *In Computer Security–ESORICS 2021: 26th European Symposium on Research in Computer Security, Darmstadt, Germany, October 4–8, 2021, Proceedings, Part II 26 (pp. 523-542). Springer International Publishing.*\n* Holohan, N., 2023. [Random Number Generators and Seeding for Differential Privacy](https://doi.org/10.48550/arXiv.2307.03543). *ArXiv e-prints 2307.03543 [cs.CR].*\n* Holohan, N., Braghin, S. and Suliman, M., 2024. [Securing Floating-Point Arithmetic for Noise Addition](https://doi.org/10.1145/3658644.3690347). *In Proceedings of the 2024 on ACM SIGSAC Conference on Computer and Communications Security (pp. 1954-1966).*\n\n## Acknowledgement\nWork in this repository was partially supported by the European Union's Horizon research and innovation programme under grant numbers 951911 (AI4Media) and 101070473 (FLUIDOS).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FIBM%2Fdifferential-privacy-library","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FIBM%2Fdifferential-privacy-library","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FIBM%2Fdifferential-privacy-library/lists"}