K-匿名性简介

Python 中的数据隐私与匿名化

Rebeca Gonzalez

Data engineer

为什么 k-匿名性重要?

左侧为马萨诸塞州州长,文字"识别马萨诸塞州州长",右侧为哈佛教授 Latanya Sweeney 的图片

Python 中的数据隐私与匿名化

为何重要?

  • 有 6 人与他同一天生日
  • 其中仅 3 人为男性
  • 其 ZIP code 唯一

展示两个数据集(医疗数据与选民名单)交集的示意图,交集为邮编、生日和性别

Python 中的数据隐私与匿名化

如何防止此类攻击?

只有一条记录与州长的人口统计信息完全匹配。

若删除全部人口统计信息,数据将失去分析价值。

是否有折中方案,确保这些人口统计值在数据集中不再唯一?

Python 中的数据隐私与匿名化

k-匿名性的定义

$$ $$ $$ $$ $$ $$ 数据集中至少有 k 名个体共享对每个个体可能构成识别的一组属性。

Python 中的数据隐私与匿名化

k-匿名性的定义

一大群人正在过马路

Python 中的数据隐私与匿名化

K-匿名数据集

2-匿名:

     ZIP code    Age
0    4217        34
1    4217        34
2    1742        77
3    1742        77

数据集中用于识别的列的每种取值组合,至少出现在 k 条不同记录中。

非 2-匿名:

     ZIP code    Age
0    4217        34
1    4217        34
2    1742        77
3    1743        77
Python 中的数据隐私与匿名化

K-匿名性:术语

展示直接标识符、准标识符和敏感属性术语的示意图

Python 中的数据隐私与匿名化

医疗数据集

# Explore DataFrame 
medical_df.head()
    Age    Department   Condition
0    34    Marketing    Anxiety disorders
1    46    Finance      Flu
2    41    Finance      Flu
3    62    Marketing    Anxiety disorders
4    44    Marketing    Anxiety disorders
Python 中的数据隐私与匿名化

隐私属性

隐私属性:

  • 标识类:如 SSN、ID 号。
  • 准标识类:本数据集的 Age、Department
  • 敏感类:本数据集的 Medical condition
Python 中的数据隐私与匿名化

探索准标识符的唯一组合

# Calculate how many unique combinations are for Age and Department
medical_df.groupby(['Age','Department']).size().reset_index(name='Count')
    Age    Department    Count
0    30    Production    2
1    31    Marketing     1
2    32    Marketing     1
3    32    Production    1
4    33    Production    1
5    34    Finance       1
6    34    Marketing     1
7    34    Production    1
8    35    Marketing     1
9    36    Finance       2
10    38    Finance      1
11    38    Production   1
Python 中的数据隐私与匿名化

方法:泛化

# Generalize Age by creating 4 groups of intervals
medical_df['Age_group'] = pd.cut(medical_df['Age'], bins=4)


# Explore the dataset with intervals medical_df.head()
    Age    Department    Condition            Age_group
0    34    Marketing     Anxiety disorders    (29.964, 39.0]
1    46    Finance       Flu                  (39.0, 48.0]
2    41    Finance       Flu                  (39.0, 48.0]
3    62    Marketing     Anxiety disorders    (57.0, 66.0]
4    44    Marketing     Anxiety disorders    (39.0, 48.0]
Python 中的数据隐私与匿名化

方法:泛化

# Calculate how many unique combinations are for Age and Department
medical_df.groupby(['Age_group','Department']).size().reset_index(name='Count')
     Age_group         Department    Count
0    (29.964, 39.0]    Finance       4
1    (29.964, 39.0]    Marketing     4
2    (29.964, 39.0]    Production    6
3    (39.0, 48.0]      Finance       8
4    (39.0, 48.0]      Marketing     5
5    (39.0, 48.0]      Production    4
6    (48.0, 57.0]      Finance       3
7    (48.0, 57.0]      Marketing     2
8    (48.0, 57.0]      Production    4
Python 中的数据隐私与匿名化

方法:泛化

# Set k to be 2, for a 2-anonymous dataset
k = 2


# Calculate how many unique combinations are for Age and Department df_count = medical_df.groupby(['Age_group','Department']).size().reset_index(name='Count')
# Filter the rows that have count less than k df_count[df_count['Count'] < k]
    Age_group    Department    Count
Python 中的数据隐私与匿名化

开始做 k-匿名!

Python 中的数据隐私与匿名化

Preparing Video For Download...