clustring with the same number of point inside each cluster

조회 수: 14 (최근 30일)
Mehdi Foumani
Mehdi Foumani 2020년 1월 2일
댓글: David Morales 2022년 10월 3일
I have x and y coordinate of a set of points resulting in matrix X. As I know, idx = kmeans(X,k) is designed in a way that I can fix the number of clusters to k. However, I want to fix an additional parameter too. I want to fix the number of points inside each cluster too.
Let me give a simple example. Assume we have 99 points (and thier x and y coordinate in matrix X). Also, we know that there should be 11 clusters (that is k) and each one of clusters should contains 9 points inside. Do you have any ideas how I can force MATLAB to put exactly 9 points inside each cluster? It would be nice if it can be also shown as plot or gscatter. Thanks
  댓글 수: 2
KSSV
KSSV 2020년 1월 2일
Share the data....can give a try.
Mehdi Foumani
Mehdi Foumani 2020년 1월 2일
For example, assume the following code. Is it possible to have 11 clusters there (each with exactly 9 points inside)?
n=99;
x = randi([0 1000],n,1);
y = randi([0 1000],n,1);
all_xy=[x,y];
[idx,C] = kmeans(all_xy,11);
[~,idx] = pdist2(C,all_xy,'euclidean','Smallest',1);
gscatter(all_xy(:,1),all_xy(:,2),idx)
for i=1:n
text(all_xy(i,1),all_xy(i,2),num2str(idx(i)));hold on;
end

댓글을 달려면 로그인하십시오.

답변 (1개)

Abhishek Kumar
Abhishek Kumar 2020년 9월 1일
편집: Abhishek Kumar 2020년 9월 18일
Dear User,
As per my understanding you are able to use the k-means function in MATLAB, but you seek a functionality to fix number of points in each cluster as well. I would like to inform that such a functionality is not available right now with k-means functions. We, have recorded your issue and such a functionality might be available in upcoming releases.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by