差分隐私的机器学习模型

Python 中的数据隐私与匿名化

Rebeca Gonzalez

Data Engineer

安全共享数据

拥有相似数据的公司共享信息以改进产品与服务。
  • 包括机器学习(ML)模型

查看数据图表的人的图片

Python 中的数据隐私与匿名化

差分隐私的机器学习模型

  • 一家为多家线上商店提供服务的 SaaS 公司
  • 新伙伴加入后,可能需要数月才能收集足够数据
  • 通过 DP,SaaS 公司可鼓励伙伴共享数据

手持笔记本、屏幕上有火箭的男子插图

$$ $$ 一名男子上方,下面有多个头像图标,代表多个合作伙伴的插图

Python 中的数据隐私与匿名化

机器学习与隐私

  • 数据集包含敏感信息
  • 攻击者可利用机器学习算法的输出
Python 中的数据隐私与匿名化

机器学习与隐私

差分隐私的机器学习模型

  • 遵循相应的数据分布
  • 能保障个体隐私
Python 中的数据隐私与匿名化

差分隐私分类模型

# Import the scikit-learn naive Bayes classifier
from sklearn.naive_bayes import GaussianNB


# Import the differentially private naive Bayes classifier from diffprivlib.models import GaussianNB
Python 中的数据隐私与匿名化

非隐私分类器

from sklearn.naive_bayes import GaussianNB

# Built the non-private classifier nonprivate_clf = GaussianNB()
# Fit the model to the data nonprivate_clf.fit(X_train, y_train)
print("The accuracy of the non-private model is ", nonprivate_clf.score(X_test, y_test))
The accuracy of the non-private model is  0.8333333333333334
Python 中的数据隐私与匿名化

差分隐私分类器

from diffprivlib.models import GaussianNB as dp_GaussianNB

# Build the private classifier with empty constructor private_clf = dp_GaussianNB()
# Fit the model to the data and see the score private_clf.fit(X_train, y_train)
print("The accuracy of the private model is ", private_clf.score(X_test, y_test))
The accuracy of the private model is  0.7
PrivacyLeakWarning: Bounds have not been specified and will be calculated 
  on the data provided. This will result in additional privacy leakage.
  To ensure differential privacy and no additional privacy leakage, specify bounds for each dimension.
  "privacy leakage, specify bounds for each dimension.", PrivacyLeakWarning)
Python 中的数据隐私与匿名化

避免隐私泄露

为避免数据泄露,可通过传入 bounds 参数设定最小/最大值。 可以是:

  • 形式为 (min, max) 的元组
    • 覆盖全体数据的最小/最大值的整数
      • 例如:
        (0,100)
        
    • 每列最小/最大值的数组
      • 例如:
        ([0,1,0,2],[10,80,5,70])
        
Python 中的数据隐私与匿名化

避免隐私泄露

# Set the bounds to cover at least the min and max values 
bounds = (X_train.min(axis=0) - 1, X_train.max(axis=0) + 1)

# Built the classifier with epsilon of 0.5 dp_clf = dp_GaussianNB(epsilon=0.5, bounds=bounds)
# Fit the model to the data and see the score dp_clf.fit(X_train, y_train) print("The accuracy of the private model is ", private_clf.score(X_test, y_test))
The accuracy of the private model is  0.807000
Python 中的数据隐私与匿名化

更多关于设置 bounds

# Import random module
import random
# Set the min and max of bounds in the data plus some noise
bounds = (X_train.min(axis=0) - random.sample(range(0, 30), 12), 
          X_train.max(axis=0) + random.sample(range(0, 30), 12))


# Build the classifier with epsilon of 0.5 dp_clf = dp_GaussianNB(epsilon=0.5, bounds=bounds)
# Fit the model to the data and see the score dp_clf.fit(X_train, y_train) print("The accuracy of private classifier with bounds is ", dp_clf.score(X_test, y_test))
The accuracy of private classifier with bounds is 0.7544444444
Python 中的数据隐私与匿名化

不同的 epsilon 取值

不同 epsilon 取值的准确率对比图

Python 中的数据隐私与匿名化

让我们创建隐私保护模型!

Python 中的数据隐私与匿名化

Preparing Video For Download...