始める無料で始める

クラスタリングを確認する

前の演習で実行したクラスタリングを確認してみましょう!

前の演習の解答はすでに実行済みです。new_points は点の配列、labels はそれぞれのクラスタラベルの配列になっています。

この演習はコースの一部です

Pythonで学ぶ教師なし学習

コースを見る

演習の手順

  • matplotlib.pyplotplt としてインポートします。
  • new_points の0列目を xs、1列目を ys に代入します。
  • xsys の散布図を作成し、c=labels を指定して各点をクラスタラベルで色分けします。あわせて alpha=0.5 も指定します。
  • model.cluster_centers_ 属性を使ってセントロイドの座標を計算します。
  • centroids の0列目を centroids_x、1列目を centroids_y に代入します。
  • centroids_xcentroids_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()
コードを編集して実行