开始使用免费开始使用

使用 seaborn 可视化聚类

现在让我们使用 seaborn 模块可视化来自 Comic Con 的人流量数据集。利用 seaborn 的内置 hue 功能,可以更方便地根据聚类标签进行可视化。

数据存储在 pandas 的 DataFrame comic_con 中。x_scaledy_scaled 是某一时刻人群标准化后的 X、Y 坐标列名。cluster_labels 存放聚类标签。一个 linkage 对象存储在变量 distance_matrix 中。

本练习是课程的一部分

Python 中的聚类分析

查看课程

练习说明

  • 将 seaborn 模块按 sns 导入。
  • 使用 seaborn.scatterplot() 方法绘制散点图,并将聚类标签列传给 hue 参数。

交互式实操练习

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

# Import the seaborn module
____

# Plot a scatter plot using seaborn
sns.scatterplot(x=____, 
                y=____, 
                ____=____, 
                data = comic_con)
plt.show()
编辑并运行代码