且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

R k-means算法定制中心

更新时间:2021-10-04 01:34:57

centers参数采用整数k,在这种情况下,选择data中的k随机点作为初始中心,或者初始中心的矩阵,其列与data一样多.试试这个:

The centers parameter takes either an integer k, in which case k random points from data are chosen as initial centers, or a matrix of initial centers, with as many columns as data. Try this:

x <- rbind(matrix(rnorm(100, sd = 0.3), ncol = 2),
                 matrix(rnorm(100, mean = 1, sd = 0.3), ncol = 2))
kmeans(x,centers=3)
kmeans(x,centers=x[1:3,])