การทำให้ข้อมูลเชิงกลุ่มไม่ระบุตัวตน

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

Rebeca Gonzalez

Instructor

การทำให้เป็นกลุ่มกว้าง (Generalization)

    Age    Gender    Department    Condition
0    30    F         Finance       Anxiety disorders
1    42    M         Production    Bronchitis
2    35    F         Marketing     Dysthymia
3    39    F         Production    Dysthymia
4    40    M         Marketing     Flu
    Age    Gender    Department    Condition
0    <40   F         Finance       Anxiety disorders
1    >=40  M         Production    Bronquitis
2    <40   F         Finance       Dysthymia
3    <40   F         Production    Dysthymia
4    >=40  M         Marketing     Flu
ความเป็นส่วนตัวของข้อมูลและการทำให้ข้อมูลไม่ระบุตัวตนด้วย Python

Generalization ของข้อมูลเชิงกลุ่ม

# 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

ข้อมูลเชิงกลุ่ม

มีค่าที่เป็นไปได้จำนวนจำกัดหรือคงที่

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

การทำให้ข้อมูลเชิงกลุ่มไม่ระบุตัวตน

ฮิสโทแกรมของค่าเชิงกลุ่มในคอลัมน์ Education Field

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

การทำให้ข้อมูลเชิงกลุ่มไม่ระบุตัวตน

     Department                EducationField
0    Sales                     Life Sciences
1    Research & Development    Life Sciences
2    Research & Development    Other
3    Research & Development    Life Sciences
4    Research & Development    Medical

ชุดข้อมูลต้นฉบับ

     Department                EducationField
0    Sales                     Medical
1    Research & Development    Marketing
2    Research & Development    Life Sciences
3    Research & Development    Other
4    Research & Development    Life Sciences

ชุดข้อมูลที่ได้หลังจากสุ่มตามการกระจายความน่าจะเป็นของคอลัมน์ educationField ในชุดข้อมูลต้นฉบับ

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

การสุ่มตัวอย่างจากข้อมูล

สำนักสำมะโนประชากรสหรัฐฯ เผยแพร่ตัวอย่างข้อมูลที่เก็บรวบรวมจากประชาชนต่อสาธารณะ

ช่วยให้คำนวณรูปแบบทางสถิติในวงกว้างได้:

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

สำรวจการกระจายของข้อมูล

# Show the absolute frequencies of each unique value
hr['EducationField'].value_counts()
Life Sciences       606
Medical             464
Marketing           159
Technical Degree    132
Other                82
Human Resources      27
Name: EducationField, dtype: int64
ความเป็นส่วนตัวของข้อมูลและการทำให้ข้อมูลไม่ระบุตัวตนด้วย Python

สำรวจการกระจายของข้อมูล

# Generate a bar plot for the categories
df['BusinessTravel'].value_counts().plot(kind='bar')

แผนภูมิแท่งของค่าเชิงกลุ่มในคอลัมน์ Business Travel

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

สำรวจการกระจายของข้อมูล

# Obtain the absolute frequencies of each unique value
counts = hr['EducationField'].value_counts()

# Print the list of indexes
print(counts.index)
Index(['Life Sciences', 'Medical', 'Marketing', 
      'Technical Degree', 'Other', 'Human Resources'],
       dtype='object')
ความเป็นส่วนตัวของข้อมูลและการทำให้ข้อมูลไม่ระบุตัวตนด้วย Python

สำรวจการกระจายของข้อมูล

# Probability distributions of each unique value
counts = df['EducationField'].value_counts(normalize=True)
Life Sciences       0.412245
Medical             0.315646
Marketing           0.108163
Technical Degree    0.089796
Other               0.055782
Human Resources     0.018367
Name: EducationField, dtype: float64
ความเป็นส่วนตัวของข้อมูลและการทำให้ข้อมูลไม่ระบุตัวตนด้วย Python

สำรวจการกระจายของข้อมูล

# Values of the frequencies of each unique value
df['EducationField'].value_counts(normalize=True).values
array([0.4122449 , 0.31564626, 0.10816327, 0.08979592, 0.05578231,
       0.01836735])
ความเป็นส่วนตัวของข้อมูลและการทำให้ข้อมูลไม่ระบุตัวตนด้วย Python

การสุ่มตัวอย่างจากการกระจายเดิม

# Sample from a probability distribution
hr_sample['EducationField']= np.random.choice(counts.index, 
                                              p=counts.values, 
                                              size=len(hr))


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

การสุ่มตัวอย่างจากการกระจายเดิม

# Show the absolute frequencies of each category
hr['EducationField'].value_counts()
Life Sciences       606
Medical             464
Marketing           159
Technical Degree    132
Other                82
Human Resources      27
Name: EducationField, dtype: int64
# Show the frequencies of the resulting column
hr_sample['EducationField'].value_counts()
Life Sciences       604
Medical             493
Marketing           158
Technical Degree    120
Other                61
Human Resources      34
Name: EducationField, dtype: int64
ความเป็นส่วนตัวของข้อมูลและการทำให้ข้อมูลไม่ระบุตัวตนด้วย Python

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

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

Preparing Video For Download...