Skip to content

Instantly share code, notes, and snippets.

@randyzwitch
Created September 16, 2013 17:06
Show Gist options
  • Save randyzwitch/6583506 to your computer and use it in GitHub Desktop.
Save randyzwitch/6583506 to your computer and use it in GitHub Desktop.
kmeans guessing at 5 main clusters
#I think there are 5 main topics: Data Science, Web Analytics, R, Julia, Wordpress
kmeans5<- kmeans(dtm, 5)
#Merge cluster assignment back to keywords
kw_with_cluster <- as.data.frame(cbind(searchkeywords$'Natural Search Keyword', kmeans5$cluster))
names(kw_with_cluster) <- c("keyword", "kmeans5")
#Make df for each cluster result, quickly "eyeball" results
cluster1 <- subset(kw_with_cluster, subset=kmeans5 == 1)
cluster2 <- subset(kw_with_cluster, subset=kmeans5 == 2)
cluster3 <- subset(kw_with_cluster, subset=kmeans5 == 3)
cluster4 <- subset(kw_with_cluster, subset=kmeans5 == 4)
cluster5 <- subset(kw_with_cluster, subset=kmeans5 == 5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment