【发布时间】:2019-08-16 17:31:36
【问题描述】:
我正在使用“层次聚类”对一组单词进行聚类。我希望每个集群包含一定数量的单词,例如 2 个单词或 3 个单词。
我正在尝试为此集群修改 existing code。
我只是把 max(d) 的值也放到 Inf 中
Lm[min(d),] <- sl
Lm[,min(d)] <- sl
if (length(cluster)>2){#if it's already clustered with more than 2 points
#then dont't cluster them again by setting values to Inf
Lm[min(d), min(d)] <- Inf
Lm[max(d), max(d)] <- Inf
Lm[max(d),] <- Inf
Lm[,max(d)] <- Inf
Lm[min(d),] <- Inf
Lm[,min(d)] <- Inf
}
但是,它没有给我预期的结果,我想知道这是否是正确的方法?如何在 r 中使用约束进行这种类型的聚类?
我得到的结果示例
row V1 V2
166 -194 -38
167 166 -1
……..
240 239 239
241 240 240
242 241 241
243 242 242
244 243 243
【问题讨论】:
-
我不认为你可以在层次聚类中有这个约束。您可以尝试使用 k-means 之类的分区聚类,您可以在其中指定所需的集群数量,您可以将其设置为大致为每个集群提供所需元素数量的值。顺便说一句,链接已损坏(末尾有额外的
>)。 -
@Alexis 问题是我不知道集群的数量。链接已修复,谢谢
标签: r cluster-analysis hierarchical-clustering