I ran kmeans in r with k = 20 centers and 7 scaled variables to cluster with on a data frame with n = 100K.
Using dplyr group_by I was able to view summary data for each of the 20 clusters: the mean of var 1, var 2 etc.
I thought I understood the kmeans algorithm. Start with k centers, apply each observation to the closest centroid, recalculate the mean and repeat till no more movement.
I'm confused about the resulting centroid. I assumed that it was a single number in 7 dimensional space. However when I type (R) mycluster_object$centers
I get back a 20 * 7 table with a value for each cluster and variable.
Example:
library(dplyr)
set.seed(123)
myclustering <- kmeans(select(iris, -Species), centers = 3)
myclustering$centers
Sepal.Length Sepal.Width Petal.Length Petal.Width
1 5.006000 3.428000 1.462000 0.246000
2 6.850000 3.073684 5.742105 2.071053
3 5.901613 2.748387 4.393548 1.433871
What exactly are these numbers?
Separately, my initial goal was to order the clusters by "closeness". This is why I thought ordering by what I thought centroids to mean would help.
- What does
myclustering$centers
actually show? - Is there a way to order by clusters by how similar or close together they are, accounting for all the variables used?