โมเดล Machine Learning แบบ Differential Privacy

ความเป็นส่วนตัวของข้อมูลและการทำให้ข้อมูลไม่ระบุตัวตนด้วย Python

Rebeca Gonzalez

Data Engineer

การแชร์ข้อมูลอย่างปลอดภัย

บริษัทที่มีข้อมูลคล้ายกัน แบ่งปันข้อมูลเพื่อพัฒนาสินค้าและบริการ
  • รวมถึงโมเดล Machine Learning (ML)

ภาพของคนที่กำลังดูกราฟข้อมูล

ความเป็นส่วนตัวของข้อมูลและการทำให้ข้อมูลไม่ระบุตัวตนด้วย Python

โมเดล Machine Learning แบบ Differential Privacy

  • บริษัท SaaS ที่มีร้านค้าออนไลน์หลายแห่งเป็นพาร์ทเนอร์
  • เมื่อพาร์ทเนอร์รายใหม่เข้าร่วม อาจต้องใช้เวลาหลายเดือนกว่าจะรวบรวมข้อมูลได้เพียงพอ
  • ด้วย DP บริษัท SaaS สามารถส่งเสริมให้พาร์ทเนอร์แชร์ข้อมูลได้

ภาพวาดชายถือแล็ปท็อปที่มีจรวดพุ่งออกจากหน้าจอ

$$ $$ ภาพวาดชายที่มีไอคอนหลายคนอยู่ด้านล่าง แทนพาร์ทเนอร์หลายราย

ความเป็นส่วนตัวของข้อมูลและการทำให้ข้อมูลไม่ระบุตัวตนด้วย Python

Machine Learning และความเป็นส่วนตัว

  • ชุดข้อมูลมีข้อมูลที่ละเอียดอ่อน
  • ผู้ไม่หวังดีสามารถใช้ประโยชน์จากผลลัพธ์ของอัลกอริทึม Machine Learning ได้
ความเป็นส่วนตัวของข้อมูลและการทำให้ข้อมูลไม่ระบุตัวตนด้วย Python

Machine Learning และความเป็นส่วนตัว

โมเดล Machine Learning แบบ Differential Privacy

  • สอดคล้องกับการกระจายข้อมูลที่เกี่ยวข้อง
  • รับประกันความเป็นส่วนตัวให้กับแต่ละบุคคลได้
ความเป็นส่วนตัวของข้อมูลและการทำให้ข้อมูลไม่ระบุตัวตนด้วย Python

โมเดลการจำแนกแบบ Differential Privacy

# 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

โมเดลการจำแนกแบบ Differential Privacy

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 ได้ รูปแบบที่รองรับ:

  • Tuple ในรูปแบบ (min, max)
    • Integer ที่ครอบคลุมค่า min/max ของข้อมูลทั้งหมด
      • ตัวอย่าง:
        (0,100)
        
    • Array สำหรับค่า min และ max ของแต่ละคอลัมน์ในข้อมูล
      • ตัวอย่าง:
        ([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...