Я определяю оптимальное количество кластеров. Я хочу сравнить 2 разных способа определения оптимального количества кластеров. Таким образом, я покажу Внутреннюю сумму квадратов и Gap-Stat:
#Load the packages we will be using and read in the data
library(ggmap)
library(ggplot2)
library(tidyverse)
library(dplyr)
library(NbClust)
library(factoextra)
library(readxl)
library(kableExtra)
#Load dataset
testData6<-read_xlsx("C:/Users/David/Desktop/Data.xlsx")
#Look at the first 6 rows of data in the testData6 dataframe:
df<-head(testData6)
kable(df) %>%
kable_styling(bootstrap_options = "striped", font_size= 10, full_width = F)
set.seed(20)
Test1<-scale(na.omit(data.matrix(testData6)[-1]))
wssplot <- function(Test1, nc=10, seed=123){
wss <- (nrow(Test1)-1)*sum(apply(Test1,2,var))
for (i in 2:nc){
set.seed(seed)
wss[i] <- sum(kmeans(Test1, centers=i)$withinss)}
plot(1:nc, wss, type="b", xlab="Number of Clusters",
ylab="Within groups sum of squares")}
#Original Within Sum Squares plot
wssplot(Test1, nc=10)
fviz_nbclust(Test1, kmeans, method = "wss") +
geom_vline(xintercept = 4, linetype = 2)+
labs(subtitle = "Within Sum of Squares")
fviz_nbclust(Test1, kmeans, nstart = 20, method = "gap_stat", nboot = 100)+
labs(subtitle = "Gap-Stat")
Однако у меня возникла проблема, когда я запускаю последнюю строку кода:
Проблема :
> fviz_nbclust(Test1, kmeans, nstart = 20, method = "gap_stat", nboot = 100)+
+ labs(subtitle = "Gap-Stat")
Clustering k = 1,2,..., K.max (= 10): .. done
Bootstrapping, b = 1,2,..., B (= 100) [one "." per sample]:
.................................................. 50
.................................................. 100
Warning messages:
1: Quick-TRANSfer stage steps exceeded maximum (= 121200)
2: Quick-TRANSfer stage steps exceeded maximum (= 121200)
3: Quick-TRANSfer stage steps exceeded maximum (= 121200)
4: Quick-TRANSfer stage steps exceeded maximum (= 121200)
5: Quick-TRANSfer stage steps exceeded maximum (= 121200)
6: Quick-TRANSfer stage steps exceeded maximum (= 121200)
7: Quick-TRANSfer stage steps exceeded maximum (= 121200)
8: Quick-TRANSfer stage steps exceeded maximum (= 121200)
9: Quick-TRANSfer stage steps exceeded maximum (= 121200)
10: Quick-TRANSfer stage steps exceeded maximum (= 121200)
Может кто-нибудь помочь мне? Я не смог решить проблему. Большое спасибо!