檢視你的分群結果
現在來檢視你在上一個練習中完成的分群吧!
上一題的解答已經替你執行,所以 new_points 是點的陣列,而 labels 是這些點的叢集標籤陣列。
本練習屬於課程
Unsupervised Learning in Python
練習說明
- 匯入
matplotlib.pyplot並命名為plt。 - 將
new_points的第0欄指定給xs,將第1欄指定給ys。 - 繪製
xs與ys的散佈圖,並指定關鍵字參數c=labels以依叢集標籤著色,同時設定alpha=0.5。 - 使用
model的.cluster_centers_屬性計算重心(centroids)的座標。 - 將
centroids的第0欄指定給centroids_x,第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()