检查您的聚类结果
现在来检查一下您在上一个练习中完成的聚类吧!
上一个练习的参考解已经运行,因此 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将标记大小设置为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()