代码之家  ›  专栏  ›  技术社区  ›  user3079364

matlab中层次聚类根与子聚类的连接

  •  1
  • user3079364  · 技术社区  · 6 年前

    我使用分层聚类算法对数据集进行不同数量的聚类。例如,

    a= [1;2;3;4;5;20;21;22;28;29]
    Z=linkage(a,'ward')
    [clusterIndexes]=cluster(Z,'maxclust',2)
    

    这段代码将数据分成两部分,第一个集群包含1,2,3,4,5。我们将此集群称为A,第二个集群包含20,21,22,28,29,即集群B。

    当我运行以下脚本并将数据集群到3中时

    a= [1;2;3;4;5;20;21;22;28;29]
    Z=linkage(a,'ward')
    [clusterIndexes]=cluster(Z,'maxclust',3)
    

    它给出了(12345)=簇X,(20,21,22)=簇Y,(28,29)=簇Z的簇。

    如何以编程方式演示集群B拆分为集群Y和集群Z?

    对不起,这个天真的问题我对matlab很陌生。

    1 回复  |  直到 6 年前
        1
  •  1
  •   Matt    6 年前

    你可以用 setxor 确定两个集群之间的任何差异。使用者 union clusterY clusterZ 相比之下 clusterB 塞克索 .

    clusterB = [20 21 22 28 29];
    clusterY = [20 21 22];
    clusterZ = [28 29];
    
    setxor(clusterB, union(clusterY, clusterZ))
    
    ans =
    
      1×0 empty double row vector
    

    集群B 如果你有一个额外的号码,你可以看到下面的结果。

    clusterB = [5 20 21 22 28 29];
    setxor(clusterB, union(clusterY, [clusterZ]))
    
    ans =
    
         5