large numbers in K means

조회 수: 5 (최근 30일)
Tino
Tino 2019년 6월 15일
댓글: John D'Errico 2019년 6월 15일
I am trying to find the kmeans of 1 column with 1048575 numbers rows
and I am getting the error below
Error using kmeans (line 277)
X must have more rows than the number of clusters.
Error in svia (line 18)
[idx, C, miro , D] = kmeans(bibi, K);
Can anyone assist me in finding a solution for this.
Thanks in advance
Tino

채택된 답변

Guillaume
Guillaume 2019년 6월 15일
What's unclear about the error? You must specify less cluster than the number of rows in your matrix/vector. So make sure that K is less than size(bibi, 1) (or numel(bibi) if a vector).
  댓글 수: 2
Walter Roberson
Walter Roberson 2019년 6월 15일
It would be a problem for kmeans if bibi is a row vector instead of a column vector.
Guillaume
Guillaume 2019년 6월 15일
Not according to the doc: "If X is a numeric vector, then kmeans treats it as an n-by-1 data matrix, regardless of its orientation."

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

추가 답변 (1개)

John D'Errico
John D'Errico 2019년 6월 15일
편집: John D'Errico 2019년 6월 15일
x = rand(1048575,1);
size(x)
ans =
1048575 1
[IDX, C] = kmeans(x, 10);
C
Warning: Failed to converge in 100 iterations.
> In kmeans/loopBody (line 479)
In internal.stats.parallel.smartForReduce (line 136)
In kmeans (line 343)
C =
0.74809
0.049586
0.94968
0.2486
0.54773
0.64779
0.34794
0.14901
0.44755
0.84915
It works fine, athough It seems starved for iterations. But that is trivially solved.
However, if I make a mistake, and pass in a ROW vector instead, then I get the same error that you did.
[IDX, C] = kmeans(x', 10);
Error using kmeans (line 277)
X must have more rows than the number of clusters.
  댓글 수: 2
Guillaume
Guillaume 2019년 6월 15일
That's countrary to the documentation which says: "If X is a numeric vector, then kmeans treats it as an n-by-1 data matrix, regardless of its orientation".
I don't have the required toolbox but if that's not what happens then it should be reported as a bug.
John D'Errico
John D'Errico 2019년 6월 15일
That is indeed the statement, in R2019a. So it is indeed a bug, since the behavior runs contrary to the documentation.

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

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by