匿名化連續型資料

Data Privacy and Anonymization in Python

Rebeca Gonzalez

Instructor

連續型變數

  • 年齡
  • 身高
  • 體重
  • 溫度
  • 日期與時間
Data Privacy and Anonymization in 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
Data Privacy and Anonymization in Python

連續分佈

為資料選擇最佳連續分佈。

  • 建立長條圖
  • 嘗試各種連續函式,並擬合至長條圖。
  • 保留與長條圖誤差最小的函式。
Data Privacy and Anonymization in Python

連續分佈

Age 變數的分佈圖

Data Privacy and Anonymization in 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)
Data Privacy and Anonymization in 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
Data Privacy and Anonymization in 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
Data Privacy and Anonymization in Python

一起來練習吧!

Data Privacy and Anonymization in Python

Preparing Video For Download...