R kmeans初始化

3
在 R 编程环境中,我目前正在使用 kmeans 算法的标准实现 (类型: help(kmeans))。看起来我无法初始化起始质心。我将 kmeans 算法指定为给我 4 个聚类,并想传递起始质心的向量坐标。
1. 是否有一个实现 kmeans 允许我传递初始质心坐标的方法?

5
centers 参数应该可以让你做到这一点。 - Marius
1个回答

6

是的,你提到的实现方式允许你指定起始位置。这可以通过centers参数来传递。

> dat <- data.frame(x = rnorm(99, mean = c(-5, 0 , 5)), y = rnorm(99, mean = c(-5, 0, 5)))
> plot(dat)
> start <- matrix(c(-5, 0, 5, -5, 0, 5), 3, 2)
> kmeans(dat, start)
K-means clustering with 3 clusters of sizes 33, 33, 33

Cluster means:
           x           y
1 -5.0222798 -5.06545689
2 -0.1297747 -0.02890204
3  4.8006581  5.00315151

Clustering vector:
 [1] 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2
[51] 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3

Within cluster sum of squares by cluster:
[1] 58.05137 73.81878 52.45732
 (between_SS / total_SS =  94.7 %)

Available components:

[1] "cluster"      "centers"      "totss"        "withinss"     "tot.withinss" "betweenss"   
[7] "size"  

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接