การทำข้อมูลต่อเนื่องให้เป็นนิรนาม

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

Rebeca Gonzalez

Instructor

ตัวแปรต่อเนื่อง

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

ตัวแปรต่อเนื่อง

# See the dataset
hr.head()
    Age    BusinessTravel        Department                EducationField    EmployeeNumber
0    41    Travel_Rarely         Sales                     Life Sciences     1
1    49    Travel_Frequently     Research & Development    Life Sciences     2
2    37    Travel_Rarely         Research & Development    Other             4
3    33    Travel_Frequently     Research & Development    Life Sciences     5
4    27    Travel_Rarely         Research & Development    Medical           7
ความเป็นส่วนตัวของข้อมูลและการทำให้ข้อมูลไม่ระบุตัวตนด้วย Python

การแจกแจงต่อเนื่อง

เลือกการแจกแจงต่อเนื่องที่เหมาะสมที่สุดกับข้อมูล

  • สร้างฮิสโตแกรม
  • ทดลองใช้ฟังก์ชันต่อเนื่อง โดย Fit เข้ากับฮิสโตแกรม
  • เลือกฟังก์ชันที่มีค่า Error น้อยที่สุดเมื่อเทียบกับฮิสโตแกรม
ความเป็นส่วนตัวของข้อมูลและการทำให้ข้อมูลไม่ระบุตัวตนด้วย Python

การแจกแจงต่อเนื่อง

กราฟแสดงการแจกแจงของตัวแปร Age

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

การนำการแจกแจงไปใช้

import scipy.stats


# Fit the genlogistic distribution to the continuous variable Age params = scipy.stats.genlogistic.fit(hr['Age'])
# See the parameters of the continuous functions print(params)
(4.9899067653418285, 22.32808853181744, 7.046590524738551)
ความเป็นส่วนตัวของข้อมูลและการทำให้ข้อมูลไม่ระบุตัวตนด้วย Python

การสุ่มตัวอย่างจากการแจกแจงต่อเนื่อง

# Sample from the genlogistic distribution
df['Age'] = scipy.stats.genlogistic.rvs(size=len(df.index), *params)


# See the resulting dataset df['Age'].head()
     Age          BusinessTravel     Department                EducationField    EmployeeNumber
0    40.767259    Travel_Rarely      Sales                     Life Sciences     1
1    45.730504    Travel_Frequently  Research & Development    Life Sciences     2
2    41.910050    Travel_Rarely      Research & Development    Other             4
3    35.275320    Travel_Frequently  Research & Development    Life Sciences     5
4    40.198134    Travel_Rarely      Research & Development    Medical           7
ความเป็นส่วนตัวของข้อมูลและการทำให้ข้อมูลไม่ระบุตัวตนด้วย Python

การสุ่มตัวอย่างจากการแจกแจงต่อเนื่อง

# Round the values to obtain discrete values
df['Age'] = df['Age'].round()
     Age   BusinessTravel     Department                EducationField    EmployeeNumber
0    41    Travel_Rarely      Sales                     Life Sciences     1
1    46    Travel_Frequently  Research & Development    Life Sciences     2
2    42    Travel_Rarely      Research & Development    Other             4
3    35    Travel_Frequently  Research & Development    Life Sciences     5
4    40    Travel_Rarely      Research & Development    Medical           7
ความเป็นส่วนตัวของข้อมูลและการทำให้ข้อมูลไม่ระบุตัวตนด้วย Python

มาฝึกกันเถอะ!

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

Preparing Video For Download...