IBM Differential Privacy Library

repository·main·Indexed 21 days ago

https://github.com/ibm/differential-privacy-library

A general-purpose library for differential privacy (DP) designed for research and education. It provides a collection of DP mechanisms (Laplace, Gaussian, Exponential, Geometric), machine learning models that act as drop-in replacements for sklearn (including GaussianNB, LogisticRegression, and KMeans), and tools for differentially private data analysis such as histograms and statistical utilities. It also includes the BudgetAccountant class for tracking privacy budget consumption.

Tokens
9K
Snippets
28
Records
51
Agent score
74%

What's inside diffprivlib

  1. Welcome to the IBM Differential Privacy Library

    main
    The IBM Differential Privacy Library is a specialized library for differential privacy and machine learning. It provides a common codebase and building blocks to enable the experimentation, simulation, and implementation of differentially private models.
  2. Use classification models in diffprivlib.models

    main

    The diffprivlib.models module provides differentially private implementations of common classification algorithms. These models are designed to provide privacy guarantees while performing tasks like categorization.

    Available classification models include:

    • GaussianNB: Gaussian Naive Bayes
    • LogisticRegression: Logistic Regression
    • RandomForestClassifier: Tree-based ensemble model
    • DecisionTreeClassifier: Single decision tree model
  3. Overview of diffprivlib components

    main

    The library is organized into four major functional areas:

    1. Mechanisms: The fundamental building blocks of differential privacy. These are low-level components intended for experts implementing custom models or conducting separate investigations.
    2. Models: A collection of machine learning models that implement differential privacy. This includes models for clustering, classification, regression, dimensionality reduction, and pre-processing. These models are designed to be drop-in replacements for sklearn models.
    3. Tools: Generic tools for differentially private data analysis, such as differentially private histograms (which follow the same format as numpy.histogram).
    4. Accountant: Includes the BudgetAccountant class, used to track the privacy budget and calculate total privacy loss using advanced composition techniques.
  4. Use BudgetAccountant for privacy budget tracking

    main
    The BudgetAccountant class in diffprivlib.accountant serves as the base class for managing and tracking the privacy budget (epsilon and delta) consumed during a sequence of differentially private operations. It provides the foundational logic for accounting for privacy loss across multiple queries or data releases.
  5. Understand the core hierarchy of diffprivlib.mechanisms

    main

    The diffprivlib.mechanisms module provides various differential privacy mechanisms used to add noise to data. The hierarchy is built upon several base classes:

    • DPMachine: The top-level base class for differential privacy machines.
    • DPMechanism: The base class for specific DP mechanisms.
    • TruncationAndFoldingMixin: A mixin providing functionality for truncation and folding operations used by certain mechanisms.

    When implementing or using custom mechanisms, you are interacting with these core abstractions.

  6. Explore diffprivlib through example notebooks

    main

    The diffprivlib repository provides a collection of Jupyter notebooks that demonstrate various use cases, ranging from basic machine learning to advanced privacy budget management. These notebooks are organized by increasing complexity:

    • Machine Learning Basics:
      • 30seconds.ipynb: A quick introduction to training a machine learning model with differential privacy.
      • naive_bayes.ipynb: Training a Naive Bayes classifier (using the UCI adult dataset).
      • logistic_regression.ipynb: Training a logistic regression classifier (using the UCI adult dataset).
      • linear_regression.ipynb: Training a linear regressor (using the UCI diabetes dataset).
    • Data Analysis & Utilities:
      • histograms.ipynb: Using the histogram function to plot data distributions.
      • exploration.ipynb: An example workflow for data exploration using diffprivlib.
    • Advanced Privacy Management:
      • accountant.ipynb: Using the BudgetAccountant class to track privacy budget consumption across multiple operations.
      • pipeline.ipynb: Integrating diffprivlib with sklearn pipelines to train differentially private models.
  7. Install diffprivlib manually from source

    main

    To install from source, clone the repository and run the installation command from the project folder.

    git clone https://github.com/IBM/differential-privacy-library
    cd differential-privacy-library
    pip install .

    Alternatively, you can use python3 -m pip install . within the project directory.

    git clone https://github.com/IBM/differential-privacy-library
    pip install .