Skip to content

Instantly share code, notes, and snippets.

@iluxonchik
Created October 23, 2017 07:21
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 iluxonchik/d4f368e71b605683394355d7bfcba071 to your computer and use it in GitHub Desktop.
Save iluxonchik/d4f368e71b605683394355d7bfcba071 to your computer and use it in GitHub Desktop.
findWSS <- function(data) {
print(paste("[TRACER] Finding WSS.."))
start <- Sys.time()
wss <- (nrow(data)-1)*sum(apply(data,2,var))
for (i in 2:length(unique(data))) {
wss[i] <- sum(kmeans(data, centers=i)$withinss)
}
plot(1:length(unique(data)), wss, type="b", xlab="Number of Clusters", ylab="Within groups sum of squares")
end <- Sys.time()
print(paste("[TIMER] Finding WSS:", difftime(end, start), "secs"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment