R kmeans initialization

后端 未结 1 1726
心在旅途
心在旅途 2020-12-17 06:11

In the R programming environment, I am currently using the standard implementation of the kmeans algorithm (type: help(kmeans)). It appears that I

相关标签:
1条回答
  • 2020-12-17 06:37

    Yes. The implementation you mention allows you to specify starting positions. You pass them in through the centers parameter

    > 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"  
    
    0 讨论(0)
提交回复
热议问题