A problem with K-means Clustering
3 次查看(过去 30 天)
显示 更早的评论
X = rand(1482,74);
nCluster = 12;
[idx,sumd] = kmeans(X,2);
%%
for pp = 3 : nCluster
[~, index_max_cluster] = max(sumd);
max_wcss_cluster = X(idx==index_max_cluster, :);
[idx,sumd] = kmeans(max_wcss_cluster,2);
end
I need to bisecting K-means to a dataset, but I can't resolve this error. Maybe it's because I have to merge all the data into a cluster first?
How can I solve?
0 个评论
采纳的回答
Cris LaPierre
2022-6-14
Perhaps you could describe what you think your code is doing?
One thing to be aware of - outputs are determined by position, not variable name. If you want to capture sumd as an output of kmeans, it is captured in the third output.
That would look like this
X = rand(1482,74);
[idx,C,sumd] = kmeans(X,2);
The error you are getting is because you are using idx==index_max_cluster, but since the dimensions don't match (idx is 758x1 while index_max_cluster is 1x74), implicit expansion is turing the comparison into a 758x74 matrix. When used to index X, the matrix is turned into a vector of 758*74=56092 elements. However, X only has 1482 elements. It is the combination of these size mismatches that is generating the error.
6 个评论
Cris LaPierre
2022-6-14
Ok, then you can mark this question as answered. If you have a new question, feel free to start a new post for it.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!