数据 集 USArrests包含统计数据,即1973年美国50个州中每100,000名居民因 袭击、谋杀 和 强奸而被捕的人数。
袭击的人数和、谋杀人数是相关吗 ?
ggplot(USArrests) +
aes(x = Murder , y = Assault ) +
geom_point() + stat_smooth()
袭击的人数和谋杀人数的散点图,说明了袭击的人数和谋杀人数是相关
如果做kmeans聚类,最好的K值是多少?
df <- scale(USArrests)
library(factoextra)
set.seed(123)
library(cluster)
gap_stat <- clusGap(df, FUN = kmeans, nstart = 25, K.max = 10, B = 500)
fviz_gap_stat(gap_stat)
最好的K值应该选择4
kmeans聚类的结果
km.res <- kmeans(df, 4, nstart = 25)
fviz_cluster(km.res, USArrests)
<