クラスタリングの結果を確認する
前の演習で行ったクラスタリングの結果を確認してみましょう。
前の演習の解答は実行済みです。そのため、new_pointsには点の配列が、labelsにはそれぞれの点のクラスターラベルの配列が格納されています。
この演習はコースの一部です
Pythonで学ぶ教師なし学習
演習の手順
matplotlib.pyplotをpltとしてインポートしてください。new_pointsの列0をxsに、new_pointsの列1をysに割り当ててください。xsとysの散布図を作成してください。c=labelsキーワード引数を指定して、点をクラスターラベルごとに色分けし、alpha=0.5も指定してください。modelの.cluster_centers_属性を使って、セントロイドの座標を計算してください。centroidsの0列をcentroids_xに、centroidsの1列をcentroids_yに割り当ててください。centroids_xとcentroids_yの散布図を作成してください。markerパラメータに'D'(ダイヤモンド)を指定してマーカーの形を設定し、s=50でマーカーのサイズを50に設定してください。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Import pyplot
____
# Assign the columns of new_points: xs and ys
xs = ____
ys = ____
# Make a scatter plot of xs and ys, using labels to define the colors
____
# Assign the cluster centers: centroids
centroids = ____
# Assign the columns of centroids: centroids_x, centroids_y
centroids_x = centroids[:,0]
centroids_y = centroids[:,1]
# Make a scatter plot of centroids_x and centroids_y
____
plt.show()