Created
September 22, 2015 15:11
-
-
Save MarkEdmondson1234/db1cefd7fa498ff5c319 to your computer and use it in GitHub Desktop.
For Machine Learning and Web Analytics blogpost http://markedmondson.me/intro-to-machine-learning-with-web-analytics-random-forests-and-k-means
This file contains 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
# 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