首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >R聚类分析Ward聚类中心

R聚类分析Ward聚类中心
EN

Stack Overflow用户
提问于 2021-04-10 20:06:04
回答 1查看 30关注 0票数 0

我使用hclust中的欧几里德距离和Ward.D2方法在R中进行了聚类分析。我想使用这些聚类中心作为K-means分析的起点。但是我不知道如何提取Ward方法的中心?有谁能帮帮忙吗?

EN

回答 1

Stack Overflow用户

发布于 2021-04-11 06:39:58

下面是一个使用虹膜数据集的可重现的例子:

代码语言:javascript
复制
data(iris)
iris.z <- scale(iris[, -5])                            # Standardize the variables
iris.hcl <- hclust(dist(iris.z), method="ward.D2")     # Compute clusters
iris.hcl3 <- cutree(iris.hcl, 3)                       # Cut at 3 clusters
centers <- aggregate(iris.z, by=list(iris.hcl3), mean) # Compute centroids
iris.km3 <- kmeans(iris.z, centers[, -1])              # Compute kmeans
addmargins(xtabs(~iris.hcl3+iris.km3$cluster))         # Compare results
#      iris.km3$cluster
# iris.hcl3   1   2   3 Sum
#       1    49   0   0  49
#       2     1  29   0  30
#       3     0  24  47  71
#       Sum  50  53  47 150

请注意,hcl3中的1行从集群2移到了km3中的集群1,hcl3中的24行从集群3移到了km3中的集群2。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67034184

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档