開始使用免費開始

檢視你的分群結果

現在來檢視你在上一個練習中完成的分群吧!

上一題的解答已經替你執行,所以 new_points 是點的陣列,而 labels 是這些點的叢集標籤陣列。

本練習屬於課程

Unsupervised Learning in Python

檢視課程

練習說明

  • 匯入 matplotlib.pyplot 並命名為 plt
  • new_points 的第 0 欄指定給 xs,將第 1 欄指定給 ys
  • 繪製 xsys 的散佈圖,並指定關鍵字參數 c=labels 以依叢集標籤著色,同時設定 alpha=0.5
  • 使用 model.cluster_centers_ 屬性計算重心(centroids)的座標。
  • centroids 的第 0 欄指定給 centroids_x,第 1 欄指定給 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()
編輯並執行程式碼