始める無料で始める

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

前の演習で行ったクラスタリングの結果を確認してみましょう。

前の演習の解答は実行済みです。そのため、new_pointsには点の配列が、labelsにはそれぞれの点のクラスターラベルの配列が格納されています。

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

Pythonで学ぶ教師なし学習

コースを見る

演習の手順

  • matplotlib.pyplotpltとしてインポートしてください。
  • new_pointsの列0xsに、new_pointsの列1ysに割り当ててください。
  • xsysの散布図を作成してください。c=labelsキーワード引数を指定して、点をクラスターラベルごとに色分けし、alpha=0.5も指定してください。
  • model.cluster_centers_属性を使って、セントロイドの座標を計算してください。
  • centroids0列をcentroids_xに、centroids1列をcentroids_yに割り当ててください。
  • centroids_xcentroids_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()
コードを編集して実行