Now, 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.
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.
We 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!).
clf.predict(X_test)
Every 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!
Congratulations, you've completed your first differentially private machine learning task with the Differential Privacy Library! Check out more examples in the notebooks directory, or dive straight in.
Contents
Diffprivlib is comprised of four major components:
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.
Models: This module includes machine learning models with differential privacy. Diffprivlib currently has models for clustering, classification, regression, dimensionality reduction and pre-processing.
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.
Accountant: The BudgetAccountant class can be used to track privacy budget and calculate total privacy loss using advanced composition techniques.
Setup
Installation with pip
The library is designed to run with Python 3.
The library can be installed from the PyPi repository using pip (or pip3):
pip install diffprivlib
Manual installation
For the most recent version of the library, either download the source code or clone the repository in your directory of choice:
To install diffprivlib, do the following in the project folder (alternatively, you can run python3 -m pip install .):
pip install .
The 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:
pytest
Citing diffprivlib
If you use diffprivlib for research, please consider citing the following reference paper:
@article{diffprivlib,
title={Diffprivlib: the {IBM} differential privacy library},
author={Holohan, Naoise and Braghin, Stefano and Mac Aonghusa, P{\'o}l and Levacher, Killian},
year={2019},
journal = {ArXiv e-prints},
archivePrefix = "arXiv",
volume = {1907.02444 [cs.CR]},
primaryClass = "cs.CR",
month = jul
}
请发表评论