Created
September 17, 2013 17:38
-
-
Save randyzwitch/6597784 to your computer and use it in GitHub Desktop.
Repeated k-means to calculate elbow graph
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#accumulator for cost results | |
cost_df <- data.frame() | |
#run kmeans for all clusters up to 100 | |
for(i in 1:100){ | |
#Run kmeans for each level of i, allowing up to 100 iterations for convergence | |
kmeans<- kmeans(x=dtm, centers=i, iter.max=100) | |
#Combine cluster number and cost together, write to df | |
cost_df<- rbind(cost_df, cbind(i, kmeans$tot.withinss)) | |
} | |
names(cost_df) <- c("cluster", "cost") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment