how to save number of organization for each cluster in k mean clustering.
1 次查看(过去 30 天)
显示 更早的评论
i am making 4 clusters using k mean clustering. i want to get and save the indexes of the data which are a part of each cluster how can i?
%% matlab code
clc
clear all
close all
radius=15;
X0=0; % x-coordinate of Centre of the circle
Y0=0; % y-coordinate of Centre of circle
% Users
K=4;
t = 2*pi*rand(K,1);
R = radius*sqrt(rand(K,1));
x_u = X0 + R.*cos(t); % X-coordinate of the Users
y_u = Y0 + R.*sin(t); % Y-coordinate of the Users
X3=[-6.189; -3.251; 2.926; 6.534; 10.79; 5.203; -4.465; 1.42; -8.66; -0.8748; 6.534 ; 11.251 ;0.7298; 3; -5.23; 11.86; x_u] ;
Y3=[ 1.393; 10.42; 6.639; 5.821; 8.425; 2.924; 1.139; 0.7508; -7.917; -6.928; -10.01; -7.03; 12.48; -1.497; -6.139; -3.23; y_u ];
x_b=[0.7298; 3; -5.23; 11.86];
y_b=[12.48; -1.497; -6.139; -3.23];
P = [X3 Y3] ; % points
G = 4 ; % number of groups
C = [x_u+x_b/2 y_u+y_b/2] ; % centroids
idx = kmeans(P,G,'MaxIter',10,'Start',C);
gscatter(P(:,1),P(:,2),idx)
i want to store that which index value is a part of particular cluster e.g X3(2) is a part of which cluster. i want to store index 2 basically and simarly for all values
6 个评论
采纳的回答
Walter Roberson
2022-3-30
radius=15;
X0=0; % x-coordinate of Centre of the circle
Y0=0; % y-coordinate of Centre of circle
% Users
K=4;
t = 2*pi*rand(K,1);
R = radius*sqrt(rand(K,1));
x_u = X0 + R.*cos(t); % X-coordinate of the Users
y_u = Y0 + R.*sin(t); % Y-coordinate of the Users
X3=[-6.189; -3.251; 2.926; 6.534; 10.79; 5.203; -4.465; 1.42; -8.66; -0.8748; 6.534 ; 11.251 ;0.7298; 3; -5.23; 11.86; x_u] ;
Y3=[ 1.393; 10.42; 6.639; 5.821; 8.425; 2.924; 1.139; 0.7508; -7.917; -6.928; -10.01; -7.03; 12.48; -1.497; -6.139; -3.23; y_u ];
x_b=[0.7298; 3; -5.23; 11.86];
y_b=[12.48; -1.497; -6.139; -3.23];
P = [X3 Y3] ; % points
G = 4 ; % number of groups
C = [x_u+x_b/2 y_u+y_b/2] ; % centroids
[idx, C] = kmeans(P,G,'MaxIter',10,'Start',C);
P_by_cluster = splitapply(@(varargin) varargin, P, idx);
C
P_by_cluster
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!