Skip to content

Instantly share code, notes, and snippets.

@MarkEdmondson1234
Created September 22, 2015 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarkEdmondson1234/db1cefd7fa498ff5c319 to your computer and use it in GitHub Desktop.
Save MarkEdmondson1234/db1cefd7fa498ff5c319 to your computer and use it in GitHub Desktop.
# Determine number of clusters
## run kmeans for varying number of clusters 1 to 15
wss <- (nrow(comp)-1)*sum(apply(comp,2,var))
for (i in 2:15) wss[i] <- sum(kmeans(comp,
centers=i)$withinss)
plot(1:15, wss, type="b", xlab="Number of Clusters",
ylab="Within groups sum of squares")
# From scree plot elbow occurs at k = 4-6
# we'll choose 4 clusters:
k <- kmeans(comp, 4, nstart=25, iter.max=1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment