使用“质心”和“中值”方法的树状图上的R Cutree产生比预期更多的簇

时间:2018-12-31 12:58:34

标签: r hierarchical-clustering dendrogram dendextend

我想用“质心”和“中位数”方法测试分层聚类。我有以下R代码:

library(dendextend)

iris <- datasets::iris
iris2 <- iris[,-5]
species_labels <- iris[,5]

d_iris <- dist(iris2)
hc_iris <- hclust(d_iris, method = "centroid")

dend <- as.dendrogram(hc_iris)
dend <- color_branches(dend, k=3)

plot(dend, 
    main = "Clustered Iris data set
    (the labels give the true flower species)", 
    horiz =  TRUE,  nodePar = list(cex = .007))

簇的数量似乎大于k函数中的color_branches

enter image description here

但是,如果我直接在cutree上进行hc_iris,这是分层聚类的结果:

table(cutree(hc_iris, k=3), iris$Species)

我得到3个群集,如预期的那样:

   setosa versicolor virginica
     50          0         0
     0         50        48
     0          0         2

但是如果我在树状图上应用cutree函数,则簇数为34:

table(cutree(as.dendrogram(hc_iris), 3), iris$Species)
setosa versicolor virginica
   4          0         0
   3          0         0
   3          0         0
   6          0         0
   2          0         0
   3          0         0
  10          0         0
   5          0         0
   4          0         0
   1          0         0
   1          0         0
   2          0         0
   1          0         0
   3          0         0
   2          0         0
   0          3         0
   0         27         9
   0         12         0
   0          2         0
   0          3         0
   0          1         3
   0          2         0
   0          0         9
   0          0         3
   0          0         6
   0          0         2
   0          0         3
   0          0         3
   0          0         3
   0          0         2
   0          0         2
   0          0         2
   0          0         1
   0          0         2

“质心”和“中位数”方法均会发生这种情况。

0 个答案:

没有答案