当前位置:网站首页>R language usarrests dataset visualization

R language usarrests dataset visualization

2022-06-22 20:54:00 Mrrunsen

data Set USArrests Contains statistics , namely 1973 In the U.S. 50 Every state 100,000 Resident factors attack 、 Murder and The number of people arrested for rape .

The number of attacks and 、 Is the number of murders relevant ?

ggplot(USArrests) +
  aes(x = Murder  , y = Assault ) + 
  geom_point()   + stat_smooth() 


A scatter plot of the number of attacks and murders , It shows that the number of attacks is related to the number of murders

If you do kmeans clustering , first-class K What is the value ?

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)


first-class K Value should be selected 4

kmeans The result of clustering

km.res <- kmeans(df, 4, nstart = 25)
fviz_cluster(km.res, USArrests)

原网站

版权声明
本文为[Mrrunsen]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206221917182169.html