シードがクラスタ分割に与える影響
はっきりしたクラスタ構造がないデータセットでは、シードの設定が結果に影響することに気づきました。この演習では、クラスタが明確に分かれている 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()