OpenMined / PyDP

The Python Differential Privacy Library. Built on top of: https://github.com/google/differential-privacy
Apache License 2.0
500 stars 138 forks source link

Added file for mechanism sklearn support #381

Closed grilhami closed 3 years ago

grilhami commented 3 years ago

Support for Laplace operator for SKLean pipeline is included

Description

A new file called sklearn_pipeline.py is added in the src/pydp/ml/mechanisms directory to hold all supported noise operators for the SKLearn pipeline. In the file, a class named LaplaceMechanism is provided as a prototype for the feature starting with the Laplace noise mechanism.

Affected Dependencies

The operator is dependant to SKLean library.

How has this been tested?

To use the feature, import the mechanism like so:

from pydp.ml.mechanisms.sklearn_pipeline import LalplaceMechanism

The, the operator can be used in an sklearn pipeline like so:

pipe = Pipeline([
    ('scaler', StandardScaler()),
    ('laplace', LaplaceMechanism(epsilon=0.1, sensitivity=1)), 
    ('nb', GaussianNB())
])

Checklist

review-notebook-app[bot] commented 3 years ago

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

grilhami commented 3 years ago

@chinmayshah99 Sure thing. Added the examples in the last commit.

The example notebook covers multiple sample code, including on how to set sensitivity as a function instead of a number, and budget accountant