一様データでのエルボー法
前の演習では、はっきりとしたクラスタをもつデータでエルボープロットを作成しました。ここでは、一様に分布した点からなるデータセットでエルボープロットがどのように見えるかを確認します。演習を進める前に、データ点を表示しておくとよいでしょう。
データは pandas の DataFrame uniform_data に保存されています。x_scaled と y_scaled は、標準化済みの各点の X 座標と Y 座標の列名です。
この演習はコースの一部です
Pythonで学ぶクラスタ分析
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
distortions = []
num_clusters = range(2, 7)
# Create a list of distortions from the kmeans function
for i in ____:
cluster_centers, distortion = ____
____.append(____)
# Create a DataFrame with two lists - number of clusters and distortions
elbow_plot = pd.DataFrame({'num_clusters': ____, 'distortions': ____})
# Creat a line plot of num_clusters and distortions
sns.____(x=____, y=____, data=____)
plt.xticks(num_clusters)
plt.show()