开始使用免费开始使用

随机种子对不同聚类的影响

您已经在一个并不存在明确聚类分组的数据集上观察到随机种子的影响。本练习将探索在 Comic Con 数据(聚类分组清晰)中,随机种子是否也会影响聚类结果。

数据保存在 pandas 的 DataFrame comic_con 中。x_scaledy_scaled 是某一时刻人群位置的标准化 X、Y 坐标对应的列名。

本练习是课程的一部分

Python 中的聚类分析

查看课程

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Import random class
____

# Initialize seed
random.____(____)

# Run kmeans clustering
cluster_centers, distortion = kmeans(comic_con[['x_scaled', 'y_scaled']], 2)
comic_con['cluster_labels'], distortion_list = vq(comic_con[['x_scaled', 'y_scaled']], cluster_centers)

# Plot the scatterplot
sns.scatterplot(x='x_scaled', y='y_scaled', 
                hue='cluster_labels', data = comic_con)
plt.show()
编辑并运行代码