user579674
user579674

Reputation: 2169

How to find coordinates of cluster in k-means

I'm trying to use k-means clustering on a vector of type key-values. My question is, how do I set the coordinates of each element in the vector? Specifically the key-value pairs are strings-floats. I need this to find later the center of the cluster.

Upvotes: 0

Views: 2822

Answers (2)

Ari B. Friedman
Ari B. Friedman

Reputation: 72731

K-means algorithms do generally compute centroids of clusters. For instance, in R's implementation:

n.clin <- 10
n.pop <- 100
clinicdat <- data.frame( x=runif(n.clin), y=runif(n.clin) )
popdat <- data.frame( x=runif(n.pop), y=runif(n.pop), pop=sample(1:5000, n.pop) )
plot(popdat$y~popdat$x, col="grey")
points(clinicdat$y~clinicdat$x, col="red")
km <- kmeans( subset(popdat,select=c(x,y)), n.clin )
points( fitted(km, method="centers"), col="green" )

enter image description here

Upvotes: 0

pathikrit
pathikrit

Reputation: 33409

Clustering algorithms typically only classify vertices to clusters. What you are looking for is a cluster-rendering algorithm which given a cluster partition of a graph renders the graph for visualization in a suitable way. I would say keep your cluster algorithm and visualization algorithms separate. Force-directed layout is a good simple cluster visualization algorithm.

And, lastly, here is a link to an implementation and another one.

Upvotes: 2

Related Questions