【问题标题】:Hierarchical clustering with specific number of data in each cluster分层聚类,每个聚类中具有特定数量的数据
【发布时间】: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 之类的分区聚类,您可以在其中指定所需的集群数量,您可以将其设置为大致为每个集群提供所需元素数量的值。顺便说一句,链接已损坏(末尾有额外的&gt;)。
  • @Alexis 问题是我不知道集群的数量。链接已修复,谢谢

标签: r cluster-analysis hierarchical-clustering


【解决方案1】:

这将很难优化,否则会产生任意糟糕的结果。因为您的大小限制违反了聚类原则。

考虑一维数据集 -100, -1, 1, 100。假设您要将集群大小限制为 2 个元素。层次聚类将首先合并 -1 和 +1,因为它们最接近。现在它们已经达到最大大小,所以现在唯一的选择是聚类 -100 和 +100,这是可能的最坏结果 - 这个聚类与整个数据集一样大。

【讨论】:

  • 这个问题是针对 Agglomerative 还是 Divisive 也一样?我的意思是,如果我尝试 Divisive,我会遇到这个问题吗?
  • Divisive 将面临非常相似的问题。你先做的 2^N 个拆分中的哪一个会在以后证明是最优的?
【解决方案2】:

只是给你一个例子来说明我对分区集群的意思:

library(cluster)
data("ruspini")

desired_cluster_size <- 3L
corresponding_num_clusters <- round(nrow(ruspini) / desired_cluster_size)

km <- kmeans(ruspini, corresponding_num_clusters)
table(km$cluster)
 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 
 3  3  2  4  2  2  2  1  3  3  2  3  2  3  3  2  6  3  2  1  3  6  2  8  4 

这绝对不能保证你在每组中会有多少观察, 它是确定性的, 但它至少给了你一个近似值。 在表格结果中,您可以看到许多集群(1 到 25)以 2 或 3 个元素结束。

【讨论】:

  • 谢谢,我之前尝试过 Kmeans,但它并没有给我想要的结果。因为我的数据非常接近,所以结果会像这样(1 2 3 4 5 6) (1 2 1 5 1 2) 一个集群可能会占用比我的系统中不应该发生的预期数据点更多的数据。
猜你喜欢
  • 2020-06-10
  • 2020-08-14
  • 2020-04-18
  • 2020-06-28
  • 2017-10-24
  • 2020-11-30
  • 2020-04-14
  • 2012-10-26
  • 1970-01-01
相关资源
最近更新 更多