2
$\begingroup$

I have multiple kmeans plots that I have generated in R. Specifically I have $5$ weeks and I generate $1$ kmeans plot per week. I am clustering on vectors. Most vectors in the $5$ kmeans plots will occur in each plot. What I am interested in determining is which vectors have changed cluster membership. To make this clear suppose I have a vector identified by the word "soccer" then I would like to see which cluster it belongs to in week1, week2, and so forth.

Testing for membership change should be a simple task, for each kmeans clustering, each point is given an ID as to which cluster it belongs. I have 4 clusters so each week our example vector with name "soccer" could be tagged $1$, $2$, $3$, or $4$. The naive solution would be to just check the tag for a particular vector each week. However, this is not the case because R randomly selects the tags for each cluster. I know this is the case because each cluster represents some class of curves. You can visibly see that the kmeans algorithm has partitioned the vectors into 4 classes of curves.

Are there ways to make the tag IDs for each cluster stay constant? That is if the cluster tagged in week1 with ID $2$ is the linear curve, then the clusters tagged $2$ in all remaining weeks will always be the linear cluster.

Are there any initial conditions I can pass to kmeans to make this happen? I posted this question here instead of stackoverflow because I believe this questions requires more understanding of the kmeans algorithm.

$\endgroup$
1
  • $\begingroup$ Or could you at least dput the list of kmeans objects? Maybe with a reduced number of observations, in order to not let the output become too large. $\endgroup$ May 4 '13 at 11:11
1
$\begingroup$

Since k-means is a randomized algorithm, you may end up plotting differences in random initialization instead of changes in your data.

I would recommend to look at deterministic algorithms. There are much more clever algorithms around than k-means these days...

$\endgroup$
2
  • $\begingroup$ can you cite an example or give a pointer to a paper listing some? $\endgroup$
    – user603
    May 4 '13 at 10:50
  • 1
    $\begingroup$ Try "Data Clustering" by Gan, Ma and Wu. But even Wikipedia has various more refined data clustering algorithms than variance minimization. For example DBSCAN and OPTICS must be covered in any reasonable book on clustering. They're some of the most cited clustering papers, and they work really well in my experiments. $\endgroup$ May 5 '13 at 16:03
1
$\begingroup$

You don't need to change anything in the main part of the code. First, get the outputs, in which ever order they are.

For making the new plots' cluster numbers same as the previous ones, you can write a function such that the new centroids which are closer to the older centroids are re-assigned to the cluster number of the older centroids. First compute the distance matrix between the new and the old centroids. Then find the index of the minimum of each row. That would map the older centroid to the newer centroid. I hope this is clear.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.