# Assigning class labels to k-means clusters

I have a very basic question on clustering. After I have found k clusters with their centroids, how do I go about interpreting the classes of the data points that I have clustered (assigning meaningful class labels to each cluster). I am not talking about validation of the clusters found.

Can it be done given a small labelled set of data points, compute to which cluster these labelled points belong to and based on type and number of points each cluster receives, decide the label? This seems pretty obvious but I don't know how standard it is to assigns labels to clusters this way.

To be clear, I want to perform unsupervised clustering that doesn't use any labels to first find my clusters. Then having found the clusters, I want to assign meaningful class labels to the clusters based on the properties of a few example datapoints.

-
I'm not sure to understand your question: usually, any k-means algorithm should return information on class membership for each data point. Are you talking about actual data points or new observations? – chl Mar 5 '13 at 22:19
@chi I suspect Riyaz is concerned about finding names with which to label the clusters and is talking about a priori naming some of the points and then using some algorithm which considers the preponderance of named points in the clusters to then name those clusters. – Glen_b Mar 5 '13 at 22:34
@Riyaz, could we use the following analogy to Factor Analysis to understand your question? Often someone will factor analyze a set of variables to cluster them into groups of variables that seem to 'hang together', but then the analyst needs to think about the nature of the variables that make up each cluster to come up w/ a name for / way of thinking about what each cluster (factor) is. Is that essentially what you're getting at here? – gung Mar 5 '13 at 23:19

If you look at the names in your kmeans object you will notice that there is a "cluster" object. This contains the class labels ordered the same as your input data. Here is a simple example that binds the cluster labels back to your data.

x <- data.frame(X=rnorm(100, sd=0.3), Y=rnorm(100, mean=1, sd=0.3))

k <- kmeans(x, 2)
names(k)
x <- data.frame(x, K=k$cluster) # You can also directly return the clusters x <- data.frame(x, K=kmeans(x, 2)$cluster)

-

Yes. What you propose is entirely standard and it is the way that standard k-means software works automatically. In the case of k-means you compute the euclidean distance between each observation (data point) and each cluster mean (centroid) and assign the observations to the most similar cluster. Then, the label of the cluster is determined by examining that average characteristics of the observations classified to the cluster relative to the averages of those relative to the other clusters.

-

The labels to the cluster may be based on the class of majority samples within a cluster. But this is true only if the number of clusters is equal to number of classes.

-