理解k意味着r中的聚类

时间:2013-07-08 16:03:11

标签: r k-means

下面的代码(减去我的问题)生成此图表:

enter image description here

我用“ - >”

标记了4个混淆区域
> m <- matrix(c(1,1,1) , ncol=3)
> 
> x <- rbind(matrix(c(1,0,1) , ncol=3),
+            matrix(c(1,1,1) , ncol=3),
+            matrix(c(1,1,0) , ncol=3),
+            matrix(c(0,1,1) , ncol=3),
+            matrix(c(0,0,1) , ncol=3),
+            matrix(c(0,0,0) , ncol=3),
+            matrix(c(1,1,1) , ncol=3),
+            matrix(c(1,1,1) , ncol=3),
+            matrix(c(1,1,0) , ncol=3),
+            matrix(c(1,0,0) , ncol=3),
+            matrix(c(0,0,1) , ncol=3),
+            matrix(c(0,0,0) , ncol=3),
+            matrix(c(0,0,1) , ncol=3),
+            matrix(c(0,1,1) , ncol=3),
+            matrix(c(1,0,1) , ncol=3),
+            matrix(c(0,1,0) , ncol=3))
> colnames(x) <- c("google", "stackoverflow", "tester")
> (cl <- kmeans(x, 3))

K-means clustering with 3 clusters of sizes 3, 10, 3
-> Where are sizes 3, 10 3 appearing  ?

Cluster means:
     google stackoverflow tester
1 0.6666667           1.0      0
2 0.5000000           0.5      1
3 0.3333333           0.0      0

-> There are three clusters, but what does each number signify ?

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

-> This looks to be created by summing the values of each matrix but seems to be unordered as second element in this vector is '2' but second element in 'x' is matrix(c(1,1,1) , ncol=3) which is '3'

Within cluster sum of squares by cluster:
[1] 0.6666667 5.0000000 0.6666667
 (between_SS / total_SS =  46.1 %)

-> what are between_SS & total_SS ?

Available components:

[1] "cluster"      "centers"      "totss"        "withinss"     "tot.withinss"
[6] "betweenss"    "size"        
> plot(x, col = cl$cluster)
> points(cl$centers, col = 1:5, pch = 8, cex = 2)
> 

从阅读此算法的实现(http://en.wikipedia.org/wiki/K-means_clustering)可以提供这些问题的答案我没有看到r如何计算这些值

1 个答案:

答案 0 :(得分:3)

<强> 1。群集大小意味着什么?

您提供了16条记录并告诉kmeans找到3个群集。它将这16条记录分为3组A:3条记录,B:10条记录和C:3条记录。

<强> 2。什么是集群意味着什么?

这些数字表示每个星团的质心(“平均”)的N维空间中的位置。你有三个集群,所以你有三种方法。您有三个维度(“google”,“stackoverflow”,“tester”),因此您可以获得每个维度的值。读取行中的数字可以得到单个质心的位置。

第3。什么是聚类矢量?

这是算法为您传递算法的每条记录提供的群集标签。还记得早些时候我说有3个大小为3,10和3的簇吗?这些簇标记为1,2和3,并且算法存储该向量中每个记录的簇标签。在这里,你可以看到有3“1”,10“2”和3“3”。这有意义吗?

<强> 4。什么是_S&amp; total_SS吗

这是ANOVA中通常使用的符号。您可能会发现这有用:http://www-ist.massey.ac.nz/dstirlin/CAST/CAST/HrandBlock/randBlock7.html

相关问题