使用 seaborn 視覺化叢集
現在用 seaborn 模組來視覺化來自 Comic Con 的人流(footfall)資料集。透過 seaborn 內建的 hue 參數來指定叢集標籤,可以更輕鬆地呈現叢集。
資料存放在 pandas 的 DataFrame comic_con 中。x_scaled 與 y_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()