クラスタリングを確認する
前の演習で実行したクラスタリングを確認してみましょう!
前の演習の解答はすでに実行済みです。new_points は点の配列、labels はそれぞれのクラスタラベルの配列になっています。
この演習はコースの一部です
Pythonで学ぶ教師なし学習
演習の手順
matplotlib.pyplotをpltとしてインポートします。new_pointsの0列目をxs、1列目をysに代入します。xsとysの散布図を作成し、c=labelsを指定して各点をクラスタラベルで色分けします。あわせてalpha=0.5も指定します。modelの.cluster_centers_属性を使ってセントロイドの座標を計算します。centroidsの0列目をcentroids_x、1列目をcentroids_yに代入します。centroids_xとcentroids_yの散布図を作成し、markerパラメータで'D'(ひし形)を指定します。マーカーのサイズはs=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()