比方说,我有这种类型的分层集群,如下图所示。为了获得聚类标签,我需要定义适当的阈值距离。例如,如果我把阈值设置为0.32,我可能会得到3个集群,如果我设置为3.5左右,我会从下图中得到2个集群
我不想使用阈值和固定距离,而是希望根据它们的合并顺序获得聚类标签
我想根据它们的合并来定义集群;比如第一次合并,第二次合并等等
例如,这里我想得到集群标签,当它们至少第一次合并时,这将是3个集群
cluster1: p1
cluster2: p3 and p4
cluster3: p2 and p5.
如果我在这里设置,则在至少发生第二次合并时查找集群。 在本例中,我将有两个集群,例如:
cluster1: p1
cluster2 = p3, p4, p2 and p5.
没有scipy
内置的方法来提取此类信息。如果没有,是否有任何方法可以从hierarchical clusteri
ng中提取此类信息?任何建议都很好
示例案例:
我的想法是,我不想硬编码任何阈值限制来定义集群的数量,而是根据它们的合并顺序找到集群。例如,如果存在p1、p2和p3,并且在一种情况下p1和p2在0.32和另一种情况下落在同一簇中,则会为p1、p2和p3添加更多数据,现在它们可能落在同一簇中,但它们簇的合并距离可能已更改。在这种情况下,p1和p2仍然在同一集群中。因此,这里定义簇的距离阈值是不相关的
由
scipy.cluster.hierarchy
函数生成的链接矩阵有一个额外字段,用于新形成的簇中的观察数:我不确定我是否完全遵循了您的示例[1],但您可以使用簇大小来定义切割深度,从而生成簇的平面列表,从而沿着这些线获得一些东西。例如,逻辑可以是“在集群大小仍然为2或更小的最后一次合并时停止”(给出第一个包含3个集群的列表)或“在集群大小为3或更大的第一次合并时停止”(给出第二个包含2个集群的列表)
下面是一个数据集示例,该数据集提供了与绘图中显示的数据集相似的层次聚类,显示了与两个示例匹配的结果:
[1]当P3和P4合并时,“至少第一次合并”不会立即发生,只剩下4个集群吗?没有理由期望“第二次合并”总是合并两对:它也可以将单个观测值与一对观测值合并。这就是为什么我建议使用集群大小而不是“N个mergings”。
相关问题 更多 >
编程相关推荐