隨機種子對聚類結果的影響
你已經觀察到在群集邊界不明確的資料集上,隨機種子會影響結果。在這個練習中,你要探索在 Comic Con 資料中,當群集劃分相當明確時,隨機種子是否仍會影響聚類結果。
資料已存放在一個 pandas DataFrame,comic_con。x_scaled 和 y_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()