【问题标题】:How to extract cluster centres from agnes for inputting into kmeans?如何从 agnes 中提取聚类中心以输入 kmeans?
【发布时间】:2015-06-09 04:27:21
【问题描述】:

One recommended method 要获得良好的聚类解决方案,首先使用层次聚类方法,选择多个聚类,然后提取质心,然后将其重新运行为预先指定中心的 K-means 聚类算法。一个玩具例子:

library(cluster)
data(animals)
ag.a  <- agnes(agriculture, method = "ward")
ag.2 <- cutree(ag.a, k = 2)

这会给我两个集群。如何以一种格式提取聚类中心,然后将其放入kmeans() 算法并将其重新应用于相同的数据?

【问题讨论】:

    标签: r cluster-analysis


    【解决方案1】:

    您可以使用聚类来分配聚类成员资格,然后计算聚类中所有观测值的中心。如果传入矩阵,kmeans 函数允许您通过 centers= 参数指定初始中心。你可以这样做

    library(cluster)
    data(animals)
    ag.a  <- agnes(agriculture, method = "ward")
    ag.2 <- cutree(ag.a, k = 2)
    
    # calculate means per group
    cent<-aggregate(cbind(x,y)~ag.2, agriculture, mean)
    # pass as initial centers
    kmeans(agriculture, cent[,-1])
    

    【讨论】:

      猜你喜欢
      • 2012-07-05
      • 2012-04-02
      • 2021-02-04
      • 2021-10-09
      • 2018-08-12
      • 2013-08-17
      • 2012-05-01
      • 2021-09-25
      相关资源
      最近更新 更多