数据预处理
聚类前的数据预处理有助于为更准确的分群做好准备。常见的一种预处理是特征缩放,它将数据中的自变量标准化到固定范围,例如 0-1 或 0-100。
在本练习中,您将对学生成绩数据集中的 parental_level_of_education 和 writing_score 两列进行聚类,数据已加载为 performance。首先,您将在不做任何预处理的情况下创建并运行一个 k-means 模型。然后,使用特征缩放对数据进行预处理后,再做一次相同的操作。
私有 k-means 模型已作为 KMeans 从 diffprivlib.models 导入。标准化缩放器 StandardScaler 和降维方法 PCA 已从 sklearn 导入。
本练习是课程的一部分
Python 中的数据隐私与匿名化
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Build the differentially private k-means model
model = KMeans(____)
# Fit the model to the data
____
# Print the inertia in the console output
print("The inertia of the private model is: ", model.inertia_)