how to save number of organization for each cluster in k mean clustering.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Maimoona Asad
am 30 Mär. 2022
Bearbeitet: Maimoona Asad
am 31 Mär. 2022
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 Kommentare
Akzeptierte Antwort
Walter Roberson
am 30 Mär. 2022
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 Kommentare
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!