我使用hclust中的欧几里德距离和Ward.D2方法在R中进行了聚类分析。我想使用这些聚类中心作为K-means分析的起点。但是我不知道如何提取Ward方法的中心?有谁能帮帮忙吗?
发布于 2021-04-11 06:39:58
下面是一个使用虹膜数据集的可重现的例子:
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。
https://stackoverflow.com/questions/67034184
复制相似问题