助力软件开发企业降本增效 PHP / java源码系统,只需一次付费,代码终身使用! 广告
## K均值聚类 > K-Means算法通过尝试分离n个相等方差组中的样本来聚类数据,从而最小化称为惯性或簇内平方和的标准。该算法需要指定簇的数量。 ### 构造函数参数 `$clustersNumber` - 要查找的集群数 `$initialization` - 初始化方法,默认kmeans ++(见下文) ``` $kmeans = new KMeans(2); $kmeans = new KMeans(4, KMeans::INIT_RANDOM); ``` ***** ## 聚类 要将样本分成簇,只需使用簇方法。它返回带有样本的簇数组。 ``` $samples = [[1, 1], [8, 7], [1, 2], [7, 8], [2, 1], [8, 9]]; Or if you need to keep your indentifiers along with yours samples you can use array keys as labels. $samples = [ 'Label1' => [1, 1], 'Label2' => [8, 7], 'Label3' => [1, 2]]; $kmeans = new KMeans(2); $kmeans->cluster($samples); // return [0=>[[1, 1], ...], 1=>[[8, 7], ...]] or [0=>['Label1' => [1, 1], 'Label3' => [1, 2], ...], 1=>['Label2' => [8, 7], ...]] ``` ***** ## 初始化方法 ### kmeans ++(默认) > K-means ++方法以智能方式选择初始聚类中心进行k均值聚类,以加速收敛。它使用DASV播种方法包括为簇找到良好的初始质心。 ### 随机 随机初始化方法选择完全随机的质心。它获得空间边界以避免将聚类质心放置在远离样本数据的位置。