【问题标题】:For hierarchical clustering, how to find the “center” in each cluster in R对于层次聚类,如何在 R 中的每个聚类中找到“中心”
【发布时间】:2020-03-11 19:26:51
【问题描述】:

我想通过软件R中的层次聚类方法知道每个聚类的中心点。在我找到聚类的代码下面,现在我想知道每个聚类的中心点。 谢谢!

library (readxl)
B1 <- read_excel ("C: / Users / Jovani / Google Drive / Google Drive PC / Work / Clustering /test.xlsx")
> A<-scale (B1)
> d<-dist(A)
> fit.average<-hclust(d,method="average")
> plot(fit.average,hang=-1,cex=.8,main="Average Linkage Clustering")
> clusters<-cutree(fit.average, k=5)
> plot(fit.average)
> rect.hclust(fit.average,k=5)

graphic image
> library (factoextra)
> fviz_cluster (list (data = A, cluster = clusters))

【问题讨论】:

  • 嗯,好问题。你可以取集群中所有成员的平均值吗?即使您将 hclust 与“平均”一起使用,但与 kmeans 不同,聚类不是使用中心完成的..
  • 是的,我可以计算均值,但我想求聚类 1 的质心与聚类 1 的所有观测值之间的距离?有可能吗?
  • 我在下面写了一些东西,看看它是否适合你。不太清楚你想做什么
  • 非常感谢!但是我想知道中心点具体是什么,每个簇的元素到中心点的距离是多少。示例:在集群 5 中,我有元素 7、8、9 和 10(见上图),我想知道这些元素中的每一个与集群 5 的中心点之间的距离。再次感谢。
  • 我相信这是一个选择。我会测试它,你能提供我这样做的代码吗?

标签: r cluster-analysis centroid


【解决方案1】:

您可以通过聚合均值来计算中心的近似值。首先模拟一些数据和集群:

set.seed(123)
A<-matrix(rnorm(400),20,20)
d<-dist(A)
fit.average<-hclust(d,method="average")
clusters<-cutree(fit.average, k=5)

你得到每个集群中每个变量的平均值:

cluster_center = aggregate(A,list(cluster=clusters),mean)
 cluster_center[,1:4]
  cluster         V1          V2         V3
1       1 -0.2665343 -0.51417960  0.9057041
2       2  0.1564301  0.07446027 -0.3107495
3       3 -0.8689263 -0.11354894 -0.1253569
4       4  0.7617505 -0.05818998  0.1162087
5       5  1.7869131  0.68864025  1.5164706

每个中心之间的距离为:

dist(cluster_center[,-1])


         1        2        3        4
2 3.807366                           
3 4.868791 4.270748                  
4 4.334099 3.897603 4.976135         
5 6.629191 5.515162 6.876456 6.548609

【讨论】:

猜你喜欢
  • 2021-02-04
  • 1970-01-01
  • 2015-08-12
  • 1970-01-01
  • 2012-03-10
  • 1970-01-01
  • 1970-01-01
  • 2018-10-22
相关资源
最近更新 更多