Kmeans matlab “Empty cluster created at iteration 1” error

后端 未结 3 933
悲&欢浪女
悲&欢浪女 2021-02-08 18:14

I\'m using this script to cluster a set of 3D points using the kmeans matlab function but I always get this error \"Empty cluster created at iteration 1\". The script I\'m usin

3条回答
  •  闹比i
    闹比i (楼主)
    2021-02-08 18:49

    If you are confident with your choice of "k=3", here is the code I wrote for not getting an empty cluster:

    [IDX,C] = kmeans(XX,3,'distance','cosine','start','sample', 'emptyaction','singleton');
    
    while length(unique(IDX))<3 ||  histc(histc(IDX,[1 2 3]),1)~=0
    % i.e. while one of the clusters is empty -- or -- we have one or more clusters with only one member
    [IDX,C] = kmeans(XX,3,'distance','cosine','start','sample', 'emptyaction','singleton');
    end  
    

提交回复
热议问题