I am using k means for clustering of users. I want to further improve my clusters formed by selecting initial centroids myself.
Since in a dataframe kmeans allot random rows as initial centroids and that impact final clusters formed.
Is there a way to assign initial centroids manually in R ? I used elbow method to get optimal number of clusters.
My code here:
for (i in 2:15) wss[i] <- sum(kmeans(db,
centers=i, iter.max = 20)$withinss)
plot(1:15, wss, type="b", xlab="Number of Clusters",
ylab="Within groups sum of squares")
fit <- kmeans(db, 7)
aggregate(db, by=list(fit$cluster),FUN=mean)
mydata <- data.frame(db, fit$cluster)