我一直试图弄清楚为什么我只能看到标有 points()的两个图之一。
set.seed(0)
SSE <- rep(0, 10)
for (i in 1:10){
km.out <- kmeans(x = iris[,1:4], centers = 3, nstart = i)
SSE[i] <- km.out$tot.withins
}
plot(1:10, SSE, xlab = "k", ylab = "SSE", type = "b")
km.out$cluster
plot(iris[,1:2], col=(km.out$cluster+1), main="Best solution k = 3", xlab="x1", ylab="x2")
points(km.out$centers, col = 1:2, pch = 8, cex = 2)
plot(iris[,3:4], col=(km.out$cluster+1), main="Best solution k = 3", xlab="x1", ylab="x2")
points(km.out$centers, col = c3:4, pch = 8, cex = 2) # didn't work, not sure why
第一个情节有重点。
第二个图,没有绘制点。
有人知道我在做什么错吗?