Calculate the updated centroids of clustering

clusteringmeans

I have 100 points on a two dimentional space. Any point $i$ is defined by the coordinates $(x_i,y_i)$.

Lets say we perform Kmeans clustering over these points and generate clusters. Now, each cluster has a centroid. If now now move one point from cluster $i$ to cluster $j$, then how can I calculate the updated centroids.

In Matlab syntax:

[idx,C]=KMeans(X,10);

where X(:,1) are x-axis coordinates and X(:,2) are y-axis coordinates.

Best Answer

The cluster centroid is the mean of all data points assigned to that cluster. The variable idx will tell you which cluster each data point was assigned to. Based on this, you can compute the mean of all points in cluster $i$ after removing the point that you are going to move to cluster $j$. Similarly, you can compute the mean of all points in cluster $j$ after adding in the new point. These are your updated centroids.

Related Question