{ "info": { "author": "Naoise Holohan", "author_email": "naoise.holohan@ibm.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "Intended Audience :: Education", "Intended Audience :: Science/Research", "License :: OSI Approved", "Natural Language :: English", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3 :: Only", "Topic :: Scientific/Engineering", "Topic :: Security", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "# IBM Differential Privacy Library\n\n[![Python versions](https://img.shields.io/pypi/pyversions/diffprivlib.svg)](https://pypi.org/project/diffprivlib/) [![PyPi version](https://img.shields.io/pypi/v/diffprivlib.svg)](https://pypi.org/project/diffprivlib/) [![Build Status](https://travis-ci.org/IBM/differential-privacy-library.svg?branch=master)](https://travis-ci.org/IBM/differential-privacy-library) [![Documentation Status](https://readthedocs.org/projects/diffprivlib/badge/?version=latest)](https://diffprivlib.readthedocs.io/en/latest/?badge=latest) [![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/IBM/differential-privacy-library.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/IBM/differential-privacy-library/context:python)\n\n## You have just found the IBM Differential Privacy Library\n\nThe IBM Differential Privacy Library is a general-purpose library for experimenting, investigating and developing applications in differential privacy.\n\nUse the Differential Privacy Library if you are looking to:\n\n- Experiment with differential privacy\n- Explore the impact of differential privacy on machine learning accuracy using basic classification and clustering models \n- Build your own differential privacy applications, using our extensive collection of mechanisms\n\nDiffprivlib is compatible with: __Python 3.4\u20133.7__.\n\n## Getting started: [ML with differential privacy in 30 seconds](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\nimport diffprivlib.models as dp\n\nclf = dp.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\n(clf.predict(X_test) == y_test).sum() / y_test.shape[0]\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, 7.9), (2.0, 4.4), (1.1, 6.9), (0.1, 2.5)]\naccuracy = list()\n\nfor epsilon in epsilons:\n clf = dp.GaussianNB(bounds=bounds, epsilon=epsilon)\n clf.fit(X_train, y_train)\n\n accuracy.append((clf.predict(X_test) == y_test).sum() / y_test.shape[0])\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/master/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](notebooks/) directory, or [dive straight in](diffprivlib/).\n\n## Contents\n\nDiffprivlib is comprised of three modules:\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 and classification.\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).\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\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/IBM/differential-privacy-library", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "diffprivlib", "package_url": "https://pypi.org/project/diffprivlib/", "platform": "", "project_url": "https://pypi.org/project/diffprivlib/", "project_urls": { "Homepage": "https://github.com/IBM/differential-privacy-library" }, "release_url": "https://pypi.org/project/diffprivlib/0.1.1/", "requires_dist": [ "numpy (>=1.15.0)", "setuptools (>=39.0.1)", "scikit-learn (>=0.20.3)", "scipy (>=1.2.1)", "joblib (>=0.13.2)", "sphinx (>=1.4) ; extra == 'docs'", "sphinx-rtd-theme ; extra == 'docs'" ], "requires_python": "", "summary": "IBM Differential Privacy Library", "version": "0.1.1" }, "last_serial": 5420139, "releases": { "0.1.1": [ { "comment_text": "", "digests": { "md5": "87847b8c8bfabf3025ff0f77cc8cb58e", "sha256": "0805d29cd509709809fd6ddf6f4c9c280bf117384cd1689a02e06533d98f1788" }, "downloads": -1, "filename": "diffprivlib-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "87847b8c8bfabf3025ff0f77cc8cb58e", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 91094, "upload_time": "2019-06-19T12:48:52", "url": "https://files.pythonhosted.org/packages/ca/8a/87dcf8723f4958d03400ef01cd761fc4c7fe8fe2305041f0e53fee4995e5/diffprivlib-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "475b656404742d2c6ec1ad2fc6ec9828", "sha256": "db3829a7e7f85edc5f488c754d90a5180a18dfb2ca60d6a1412e2323670bc02f" }, "downloads": -1, "filename": "diffprivlib-0.1.1.tar.gz", "has_sig": false, "md5_digest": "475b656404742d2c6ec1ad2fc6ec9828", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 42414, "upload_time": "2019-06-19T12:48:58", "url": "https://files.pythonhosted.org/packages/e3/d2/e34512a792dc8a794c1bea8d4bbf1755299f61cfea4920df7f11f28eb5a0/diffprivlib-0.1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "87847b8c8bfabf3025ff0f77cc8cb58e", "sha256": "0805d29cd509709809fd6ddf6f4c9c280bf117384cd1689a02e06533d98f1788" }, "downloads": -1, "filename": "diffprivlib-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "87847b8c8bfabf3025ff0f77cc8cb58e", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 91094, "upload_time": "2019-06-19T12:48:52", "url": "https://files.pythonhosted.org/packages/ca/8a/87dcf8723f4958d03400ef01cd761fc4c7fe8fe2305041f0e53fee4995e5/diffprivlib-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "475b656404742d2c6ec1ad2fc6ec9828", "sha256": "db3829a7e7f85edc5f488c754d90a5180a18dfb2ca60d6a1412e2323670bc02f" }, "downloads": -1, "filename": "diffprivlib-0.1.1.tar.gz", "has_sig": false, "md5_digest": "475b656404742d2c6ec1ad2fc6ec9828", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 42414, "upload_time": "2019-06-19T12:48:58", "url": "https://files.pythonhosted.org/packages/e3/d2/e34512a792dc8a794c1bea8d4bbf1755299f61cfea4920df7f11f28eb5a0/diffprivlib-0.1.1.tar.gz" } ] }