如何解决'grid.Call.graphics(C_polygon,x $ x,x $ y,index)中的错误:无效的颜色名称'cluster',而K表示在R中聚类?

时间:2019-07-17 13:18:33

标签: r k-means

有点历史,我试图做K意味着在18,000点的数据集上聚类,同时一次获取36个点。我还使用kmeansruns()函数来确定最佳群集数。我正在运行kmeansruns和k均值函数,它们在一个循环中顺序运行,一次运行可运行36个数据点(下面提供了代码)。但是,运行7后,它将退出,并显示错误'grid.Call.graphics(C_polygon,x $ x,x $ y,index)中的错误:   颜色名称“ cluster”无效

我尝试删除kmeansruns()函数并手动提供集群数。这样,我得到警告消息“点数太少,无法计算出椭圆”,但是获得了椭圆

   inc = 36
   ki = seq(1,18203, by=inc)

   for (i in 0:length(ki)) {

     Dat4 = Data4[ki[i+1]:ki[i+2],3:6]

     #CovMat = cov(Dat5)
     #write.table(Dat5, file="CovMatrix.csv", sep = ",", col.names = F, 
     append = T)
     #e = eigen(CovMat)
     #EValue = CovMat$values
     #write.table(EValue, file = "EigenValues.csv", sep = ",", col.names = 
     F, append = T)

     library(tidyverse)
     library(cluster)
     library(factoextra)
     library(gridExtra)

     name2 = "F:/"
     ext = ".pdf"
     path4 = paste(name2,i,ext)
     pdf(file=path4)

     library(fpc)
     m<- kmeansruns(Dat4,krange = 1:8,criterion="asw", plot=F)
     cust=m$bestk

     km = eclust(Dat4, FUNcluster = c("kmeans"), k = cust, graph = FALSE, 
     hc_metric = "euclidean")
     f = fviz_cluster(km, geom = "point", ellipse.type = "norm", 
     ellipse.level = 0.68) + ggtitle("TrainingSet")

     CenterClust = km$centers
     #Cente = c(k$centers)
     #print(Cente)
     write.table(CenterClust, file = "KMCC.csv", sep = ",", col.names = F, 
     append = T)

     grid.arrange(f, nrow = 2)

     dev.off()

   }

我希望将kmeansruns()函数确定的具有不同数量簇的簇粘贴为驱动器中的pdf文件,但是出现上述错误并退出程序。

0 个答案:

没有答案