2

当我运行 kmeans 算法时,我收到此错误:

Error in kmeans(x, 2, 15) : 
  more cluster centers than distinct data points.

如何修复此错误,它是什么意思?我认为我的数据点是不同的?

这是我的文件和我用来生成 kmeans 的 r 代码:

rnames.csv : 
"a1","a2","a3"

cells.csv : 
0,1,2,1,4,3,5,3,4

cnames.csv : 
"google","so","test"

cells = c(read.csv("c:\\data-files\\kmeans\\cells.csv", header = TRUE))
rnames = c(read.csv("c:\\data-files\\kmeans\\rnames.csv", header = TRUE))
cnames = c(read.csv("c:\\data-files\\kmeans\\cnames.csv", header = TRUE))

x <- matrix(cells, nrow=3, ncol=3, byrow=TRUE, dimnames=list(rnames, cnames))

# run K-Means
km <- kmeans(x, 2, 15)
4

1 回答 1

2

解决此问题的方法是使用:

cells = c(read.csv("c:\\data-files\\kmeans\\cells.csv", header = FALSE))
rnames = c(read.csv("c:\\data-files\\kmeans\\rnames.csv", header = FALSE))
cnames = c(read.csv("c:\\data-files\\kmeans\\cnames.csv", header = FALSE))

代替

cells = c(read.csv("c:\\data-files\\kmeans\\cells.csv", header = TRUE))
rnames = c(read.csv("c:\\data-files\\kmeans\\rnames.csv", header = TRUE))
cnames = c(read.csv("c:\\data-files\\kmeans\\cnames.csv", header = TRUE))
于 2013-06-13T21:31:30.693 回答