K-Means: Indices of C in idx
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Maurizio Cimino
el 17 de Jul. de 2019
Editada: Maurizio Cimino
el 17 de Jul. de 2019
Hello, I'm using the built-in kmeans function but I don't understand a thing. After I've applied the function, I have two output parameters: idx and C. The first one is a matrix containing, for each observation, the cluster's index where it has been classified. The second one is the matrix containing all the centroids location. Well, is there a way to know which are the indices of the centroids C inside the matrix idx? For example, I would like to know the index inside idx of C(:,1), etc.
Thank you very much.
0 comentarios
Respuesta aceptada
the cyclist
el 17 de Jul. de 2019
I'm not certain I fully understand your question, but I'll make a guess.
The centroid is not (necessarily) one of the points of the original dataset, so none of the rows of idx correspond to the centroid itself.
The centroid locations are given by the rows of C (not the columns). The row C(1,:) is the centroid for the cluster of points with idx=1. The row C(2,:) is the centroid for the cluster of points with idx=2. And so on.
If that doesn't answer your question, maybe you could comment with some clarification.
3 comentarios
the cyclist
el 17 de Jul. de 2019
Here is a trivial example where the centroids are not in the dataset:
x = [-2 -1 1 2]';
y = [0 0 0 0]';
[idx,C] = kmeans([x y],2);
figure
hold on
% Plot data points
scatter(x,y,[],idx)
% Plot centroids
h(1) = plot(C(1,1),C(1,2),'.');
h(2) = plot(C(2,1),C(2,2),'.');
set(h,'MarkerSize',24)
I am certain that MATLAB is not going to output which data point (from the original data) is the centroid, because it is not guaranteed to be in the dataset.
You could call with the syntax
[idx,C,sumd,D] = kmeans()
and find the point with the minimum within-cluster distance.
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!