我正在使用eclust
和fviz_cluster
函数在R中执行K-均值聚类。我将30000个数据点的数据集分为500个,对于每500个点,我将应用K均值。通常,这会产生约60个这样的地块,但是一旦到达第23号地块,它就会退出并出现错误
“ grid.Call.graphics(C_polygon,x $ x,x $ y,index)中的错误:无效 颜色名称“群集””
该操作的代码为:
setwd("")
Data <- read.csv("CombinedDataset.csv", header = TRUE, sep = ",")
a = 1
b = 500
for (i in Data$Serial) {
Comb_Data = Data[a:b,4:6]
#normalisation operation performed here
library(fpc)
m <- kmeansruns(Comb_Data, krange = 1:8, criterion="asw", plot=F)
cust = m$bestk
library(tidyverse)
library(cluster)
library(factoextra)
library(gridExtra)
k = eclust(Comb_Data, FUNcluster = c("kmeans"), k = cust, graph =
FALSE, hc_metric = "euclidean")
f = fviz_cluster(k, geom = "point", ellipse.type = "norm",
ellipse.level = 0.68) + ggtitle("Optimal K", cust)
grid.arrange(f, nrow = 2)
a = a + 499
b = b + 500
}
我期望大约60个群集图,但是在图23之后,它以问题中提到的错误退出。解决该问题的任何帮助将不胜感激。