【问题标题】:Counting How Many the Cluster Index计算多少簇索引
【发布时间】:2013-05-19 17:25:12
【问题描述】:

我正在使用 k-means 进行聚类,代码如下:

[g c] = kmeans(data,k,'dist','SqEuclidean');

g 是簇索引
c 是质心
k是簇的个数,我在里面输入'3'。

执行代码时,示例结果如下:

40    60    69     1
50    75    78     2
65    70    75     2
79    80    72     3
88    80    80     3
36    67    66     1
40    60    69     1
77    85    65     3
76    77    79     3

我的问题是,如何计算每个集群的集群索引?我应该写什么脚本来展示这个东西:

“Cluster1 有三个成员
Cluster2 有两个成员
Cluster3 有四个成员”

我很困惑,因为集群索引只有一个变量。有什么想法吗?

谢谢。非常感谢您的帮助。

【问题讨论】:

    标签: matlab cluster-analysis k-means counting


    【解决方案1】:

    正如博文Under-appreciated accumarray 中所解释的,这可以像这样巧妙地完成:

    clust = [1; 2; 2; 3; 3; 1; 1; 3; 3]; % your data
    accumarray(clust, ones(size(clust)))
    
    ans =
    
     3
     2
     4
    

    【讨论】:

    • 我写了代码:clust = g; accumarray(clust, ones(size(clust))),所以效率更高,因为我有100多个数据。再次谢谢你。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-13
    • 1970-01-01
    • 2020-06-16
    • 2012-10-14
    • 2023-03-30
    • 2022-01-03
    相关资源
    最近更新 更多