algorithm - R kmeans 初始化

标签 algorithm r initialization k-means

在 R 编程环境中,我目前使用的是 kmeans 算法的标准实现(类型:help(kmeans))。看来我无法初始化起始质心。我指定 kmeans 算法给我 4 个簇,我想传递起始质心的矢量坐标。

  1. 是否有 kmeans 的实现允许我传递初始质心坐标?

最佳答案

是的。您提到的实现允许您指定起始位置。您通过 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"  

关于algorithm - R kmeans 初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16390493/

相关文章:

algorithm - 识别增加图中最大流量的边

algorithm - 具有最大连续重复次数的加权随机选择

r - 使用 ggplot 在堆叠条形图中使用多个色标

r - 如何根据 R 中的向量从 data.frame 中提取值?

c++ - 如何拥有灵活的嵌套初始化器?

java - 如何在 Java 中不进行替换

algorithm - 如何简化/优化 3d 路径?

arrays - 调用矩阵中一个单元格中两个值中的一个值

c - 为什么一个字符串可以赋给一个char*指针,而不能赋给一个char[]数组呢?

OpenCV + Ubuntu 11.04 + Macbook Pro : Can't initialize webcam?