mglearn 演示 kmeans 聚类算法的三个步骤
kmeans 算法在找到数据区域簇中心时,总是交替执行两个步骤:(1)将每个数据点分配给最近的簇中心;(2)通过计算将每个簇中心设置为属于该簇的所有数据的平均值。如果簇的分配趋于收敛,或迭代次数达到设定值,算法结束。
1、mglearn 演示 kmeans 的迭代过程
import mglearn import matplotlib.pyplot as plt mglearn.plots.plot_kmeans_algorithm() plt.show()
2、按语
Initialization 代表初始化簇中心,Assign 代表为每个簇中心分配数据点,Recompute Centers 表示通过计算重新设置簇中心。Assign 和 Recompute Centers 即前面提到的交替执行的两个步骤。
非学无以广才,非志无以成学。