Clustering of data using k-means

14 ビュー (過去 30 日間)
Maria 2018 年 5 月 25 日
コメント済み: darova 2019 年 8 月 6 日
Hello, I have a vector with data and, when I plot them, they divide into four patterns, as you can see in the figure (the 2 of them in the middle are very close). I also know from the theory that I should have 4 of these curves. Because of numerical errors, I cannot analytically identify these groups. Therefore, I tried kmeans, and I used the following code
R = real(vector(1:2:end));
I = imag(vector(1:2:end));
X = [R I];
[idx,~] = kmeans(X,4,'replicates',5);%,'Distance','correlation');
figure
plot(X(:,1),X(:,2),'*')
%idx = clusterdata(X,'Maxclust',ncond,'Distance','jaccard');
figure;
plot(X(idx==1,1),X(idx==1,2),'r.','MarkerSize',12)
hold on
plot(X(idx==2,1),X(idx==2,2),'b.','MarkerSize',12)
hold on
plot(X(idx==3,1),X(idx==3,2),'k.','MarkerSize',12)
hold on
plot(X(idx==4,1),X(idx==4,2),'g.','MarkerSize',12)
legend('Cluster 1','Cluster 2','Cluster 3','Cluster 4')
However, how you can see in the figure, the clustering is horizontal, whereas it should be vertical.
I tried to tune the kmeans function with no success. I think the problem could be the different scale for the x and y data. I tried to multiply the x data for 1e2, but nothing changed. Does anyone have any idea how can I correctly cluster these data? I also attach the vector of data I am using. The values are complex conjugate, and in the plot, I am plotting only the values for the negative imaginary part.
1 件のコメント表示非表示 なし
darova 2019 年 8 月 6 日
Try clusterdata()

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

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by