Skip to content

Instantly share code, notes, and snippets.

@tvladeck
Created December 23, 2015 18:46
Show Gist options
  • Save tvladeck/3b68431c5d87fb1e6559 to your computer and use it in GitHub Desktop.
Save tvladeck/3b68431c5d87fb1e6559 to your computer and use it in GitHub Desktop.
determining optimal # of clusters in k means
mydata <- d
wss <- (nrow(mydata)-1)*sum(apply(mydata,2,var))
for (i in 2:15) wss[i] <- sum(kmeans(mydata,
centers=i)$withinss)
plot(1:15, wss, type="b", xlab="Number of Clusters",
ylab="Within groups sum of squares")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment