【问题标题】:find number of clusters in hierarchical clustering dendrogram after cutree in r在r中的cutree之后查找层次聚类树状图中的聚类数
【发布时间】:2016-04-04 15:38:19
【问题描述】:

在树状图上使用 cutree 后,我在查找簇数时遇到了一些问题。这是我的方法:

mat <- a huge matrix
hc <- (as.dist(mat), method = "average", members = NULL)  
#to cut the tree just 1 level below the maximum height
tree <- cutree(hc, h = hc$height[[length(hc$height)-1]])  

通过打印树变量,我可以看到我的树状图被切割成两个簇。我也可以使用名称(tree[tree==1])从每个集群中获取标签,但是如何在不查看数据的情况下获取集群的数量?我想根据它在树变量中的集群数量在管道中自动执行此操作。

【问题讨论】:

  • 长度(唯一(树))?
  • 我也试过那个,但它给出了它拥有的标签总数。
  • 我通过在树上运行一个循环来做到这一点,谢谢.. :)

标签: r hierarchical-clustering


【解决方案1】:

最后,我通过在切割树状图后对树对象运行循环来回答我的问题,但这可能不是最佳解决方案。并随时提出修改建议以使其更优雅..

clust <- c()
for (i in 1:length(tree)){
clust[i] <- tree[[i]]
}
length(unique(clust))  

据我所知,这应该可以给出答案..
谢谢

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-31
    • 2014-12-23
    • 1970-01-01
    • 2014-12-14
    • 1970-01-01
    • 2020-06-28
    • 2020-11-03
    • 1970-01-01
    相关资源
    最近更新 更多