K-Means 聚类
把每个点分配给最近的质心,再把质心移到所属簇的均值。重复直到簇稳定。
6 分钟难度 3/3交互演示区域不展示广告。
Clusters3Iterations0Inertia213,184
Points are colored by their nearest centroid. Each iteration moves every cross to the mean of its cluster. Inertia measures total squared distance; it decreases as the clusters tighten.
你看到的是什么
1
选择 k 个初始质心,把每个点分配给最近的质心。
2
把每个质心重新计算为所属簇中所有点的均值。
3
重复分配和更新,直到质心不再移动。
为什么重要
K-means 是客户分群、图像压缩、矢量量化和探索性数据分析的常用基线。
复杂度与细节
每次迭代:n 个点、k 个簇、d 维时为 O(n × k × d)。空间:O(n + k)。
常见问题
K-means 总能找到全局最优吗?+
不能。它收敛到依赖初始化的局部最优。可以多次运行或使用 k-means++ 改善初始质心。
怎样选择 k?+
可以使用肘部法或轮廓系数,并结合领域知识判断多少个分组有意义。