r - How to find the optimal number of clusters? -
i know question has been asked, failing implement decent plot following code:
options(digits=1) set.seed(2014) mydata <- matrix(seq(1,360),nrow=10,ncol=36) wss <- c() (i in 1:19) wss[i] <- sum(kmeans(x=mydata,centers=seq(1,360,length.out=20)[i])$withinss) plot(1:9, wss, type="b", xlab="number of clusters", ylab="within groups sum of squares")
it produces following error
error in sample.int(m, k) : cannot take sample larger population when 'replace = false'
kmeans
assumes each row data observation. if have k
rows in x
, results of $clusters
of lenth k
. here test data has 10 rows. yet specifying centers=20
when i=2
there no way 10 observations can have 20 different clusters.
Comments
Post a Comment