开始使用免费开始使用

检查您的聚类结果

现在来检查一下您在上一个练习中完成的聚类吧!

上一个练习的参考解已经运行,因此 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 将标记大小设置为 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()
编辑并运行代码