开始使用免费开始使用

均匀数据上的肘部法

在前一个练习中,您在聚类非常清晰的数据上绘制了肘部图。现在让我们看看,当数据点均匀分布时,肘部图会是什么样子。建议您在开始练习前先可视化数据点。

数据存储在 pandas 的 DataFrame uniform_data 中。x_scaledy_scaled 分别是点的标准化 X、Y 坐标对应的列名。

本练习是课程的一部分

Python 中的聚类分析

查看课程

交互式实操练习

通过完成这段示例代码来试试这个练习。

distortions = []
num_clusters = range(2, 7)

# Create a list of distortions from the kmeans function
for i in ____:
    cluster_centers, distortion = ____
    ____.append(____)

# Create a DataFrame with two lists - number of clusters and distortions
elbow_plot = pd.DataFrame({'num_clusters': ____, 'distortions': ____})

# Creat a line plot of num_clusters and distortions
sns.____(x=____, y=____, data=____)
plt.xticks(num_clusters)
plt.show()
编辑并运行代码