【问题标题】:combine results of k-means cluster which is in loop组合循环中的 k-means 簇的结果
【发布时间】:2018-11-19 11:22:52
【问题描述】:

我有 kmeans 集群,它必须将数据分成 2 个集群。这个过程在一个循环中继续,直到它达到一个条件。所以,最后我可能会得到 20 个集群。我这样做是因为我不想分配特定数量的集群。所以它必须继续分成2。

我想知道如何在 Matlab 中做到这一点?我正在使用循环,但问题是在组合数据后我必须更改簇号。 有没有什么功能可以自己做,而不是我分配新的簇号?

以下示例可以是其中一种方法。可能还有其他方法。没关系,只要给出聚类组合的结果即可。 例如:* 第一个循环:1 2 2 1 2 1 1

第二个循环:(它会采用第一个聚类并将其聚类为 2 个集合,然后将其与之前的结果相结合)

[1 1 1 1] cluster into 2 set=> [1 1 2 1]=> 与前一个循环 [1 1 3 1] 结合(它选择 3,因为我们已经有 cluster 2)

它将再次占用(子集群的)第一个集群:

[1 1 1] 后簇 => [1 1 2] => 与前一个循环 [1 1 3 4] 结合 这里有一个例子:

我的代码:

[IDX,C,SUMD] = SpectralClustering(G, k); % k is two
.
.
.
if Wav > w % Wav is average weight of cluster

            Gi = subgraph(G, IDX==1); % IDX is cluster number 
            Ctemp = union(Ctemp, SpectralClustering(Gi, k)); % k is 2
 else
            Ctemp = union(Ctemp, IDX);
 end

C = Ctemp;

【问题讨论】:

  • 如果您发布 minimal reproducible example 而不是我们只是猜测您所做的事情会容易得多。
  • @beaker,我补充了,现在好吗?
  • 您是在问如何将数字聚类到每个聚类?
  • 如果您为集群的每个“层”赋予唯一的组名,您就不必跟踪哪些整数已用于其他分支中的标签。例如1:2为第一层,11:12为第二层组1,111:112为第三层,11的分支等
  • @DMR,谢谢,但我不知道我有多少。因为有条件要检查。

标签: matlab cluster-computing


【解决方案1】:

正如我在评论中提到的,如果集群标签源自父集群,则它们将是唯一的:

function [clusters] =  clusterExample(data, parentCluster)

% On each level, cluster data into two clusters based on value relative to
% quantiles (AKA the median, when k = 2)

% Stop clustering if the ratio of the standard deviation of the cluster
% to the mean of the cluster is  <= .1 
% This is an arbitary stopping rule for this example
k = 2;

cutOffPoint = quantile(data, (1 / k));

clusters = nan(1, length(data));
clusters(data <= cutOffPoint) = (parentCluster * 10) + 1;
clusters(data > cutOffPoint) =  (parentCluster * 10) + 2;
clusterLabels = unique(clusters);
for g = clusterLabels
   clusterIdx = clusters == g;
   clusterMean = mean(data(clusterIdx));
   clusterSD = std(data(clusterIdx));
   if (clusterSD / clusterMean) > .1
       clusters(clusterIdx) = clusterExample(data(clusterIdx), g);
   end
end

使用中:

data = rand(1,100);
startCluster = 0;
clusters = clusterExample(data, startCluster);

每个生成的集群的 SD 都在集群平均值的 10% 以内(本示例使用任意停止规则)。

【讨论】:

    猜你喜欢
    • 2016-12-18
    • 2016-04-14
    • 2016-11-26
    • 1970-01-01
    • 2016-12-03
    • 2013-04-22
    • 2020-05-18
    • 2021-06-18
    • 2014-07-12
    相关资源
    最近更新 更多