【发布时间】:2020-03-30 11:51:14
【问题描述】:
我有一个数据库,我在上面进行了层次聚类(使用agnes())并且效果很好(我按照这里描述的方式进行操作:https://uc-r.github.io/hc_clustering。现在我想将数据库中的人造集群或类与那些找到层次聚类。我想我可以用tanglegram() 做到这一点。
当我已经有组时,我不知道如何生成树状图/进行层次聚类。我如何告诉 R 关于这些组的信息?
如果您能有条不紊地回答这个问题,那就太好了。
`
set.seed(73)
great <- data.frame(c0=c("r1","r2","r3","r4","r5","r6"),c1=c("0.89","46","0","0.56","12","0"),c2=c("0","0.45","45","79","0.45","4.4"))
#euclidean distance
great_dist <- dist(great)
#agglomerative with agnes()
#wards minimizes total within cluster variance
#minimum between-cluster-distance is merged
hc1_wards <- agnes(great,method ="ward")
#agglomerative coefficient
hc1_wards$ac
hc1_wards_plot <- pltree(hc1_wards, cex = 0.6, hang = -1, main = "Dendrogram\nagglomerative clustering",labels=F)
#cutting into a specific amount of clusters
#average silhouette method
fviz_nbclust(great, FUN = hcut, method = "silhouette")
# Cut tree into 2 groups
great_grp <-
agnes(great, method = "ward")
great_grp_cut <- cutree(as.hclust(great), k = 2)
#using the cutree output to add the cluster each observation belongs to sub
great_cluster <- mutate(great,cluster = great_grp_cut)
#evaluating goodness of cluster with dunn()
#with count() how many obs. in one cluster
count(great_cluster,cluster)
dunn <- clValid::dunn(distance = great_dist,clusters = great_grp_cut)
`
第 1、2、4 和 3、5、6 行是人造的伟大集群。
cl1 <- great[c(1,2,4), ]
cl2 <- great[c(3,5,6, ]
我想比较层次聚类和人为聚类。如何使用人造聚类执行树状图,以便将它们与tenglegram() 进行比较。还有其他方法可以比较它们吗?
【问题讨论】:
-
你想如何比较它们?视觉上,还是使用一些相似度指标?
-
我考虑过视觉比较以获得更好的直观理解
-
我使用的包库(tidyverse)#数据操作库(cluster)#聚类算法库(factoextra)#聚类可视化库(dendextend)#用于比较两个树状图库(plotrix)库(clValid)#邓恩指数
-
@takelTeasy - 你可能应该在问题中添加这些,也许在代码中,使用调用库的行。
标签: r compare hierarchical-clustering