Why do I get this message : Error using kmeans ---X must have more rows than the number of clusters.

3 ビュー (過去 30 日間)
Hello,
When I run a collegue script, i get this error message: Error using kmeans ---X must have more rows than the number of clusters. What are my option to solve this problem?
Thank you.
Andree

採用された回答

Kelly Kearney
Kelly Kearney 2014 年 1 月 15 日
How many data points do you have? And how many clusters are you attempting to create? You can't group 4 points into 5 clusters, for example.

その他の回答 (3 件)

Andree-Sylvie Carbonneau
Andree-Sylvie Carbonneau 2014 年 1 月 15 日
This is the code:
ab = IM1;
nrows = size(ab,1);
ncols = size(ab,2);
ab = reshape(ab,nrows*ncols,1);
nColors = 3;
[cluster_idx cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean',...
'Replicates',nColors + 1,'display','iter');
clear ab nColors
  2 件のコメント
Andree-Sylvie Carbonneau
Andree-Sylvie Carbonneau 2014 年 1 月 16 日
編集済み: Andree-Sylvie Carbonneau 2014 年 1 月 16 日
Size(ab,1)... is from the Color-Based Segmentation Using K-Means Clustering example that I found on MATHWORKS documentation center.

サインインしてコメントする。


Thulfiqar Hussein
Thulfiqar Hussein 2017 年 3 月 22 日
the value (X/K) should be integer number without fractions. for example if you have 10 objects and cluster them to 3 groups you will get 10/3 = 3.3 and this error will pop up, but if you cluster them to 2 or 5 groups there will be no problem.

Laura Hensel
Laura Hensel 2020 年 2 月 29 日
You should also check if you have any missing values in your matrix

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by