R语言 执行k均值聚类分析时,如何将数据重新组织为单个聚类?

14ifxucb  于 2023-02-26  发布在  其他
关注(0)|答案(1)|浏览(140)

我正在对具有62个变量的 Dataframe 执行k均值聚类分析:点击数字1-62和75000列。我如何将 Dataframe 组织成单独的簇?
我使用 fviz_cluster 来可视化集群:

r_fit = kmeans(pressure_rotate, 5, nstart = 25)
fviz_cluster(r_fit,data = pressure_rotate)

并且我能够使用 r_fit$cluster 命令访问一个表,该表中的变量属于哪个簇,但是我如何重新组织数据,以便能够看到每个簇包含的内容呢?

cluster 1: Tapping number 3, Tapping number 5, Tapping number 12, ...
cluster 2: Tapping number 7, tapping number 9, ....
etc
hivapdat

hivapdat1#

您有62行/观测值和75000列/变量。对吗?不是62个变量。不清楚“Tapping number”是数据中的一列还是仅仅是行号。下面是使用R中包含的iris数据的示例:

data(iris)  # 150 rows, 4 numeric variables, one species variable
iris.km <- kmeans(iris[, -5], 3, nstart=25)   # Exclude species variable
fviz_cluster(iris.km, iris[, -5])       # Make a plot showing the clusters
split(rownames(iris), iris.km$cluster)  # Show cluster membership by row name
# $`1`
#  [1] "51"  "52"  "54"  "55"  "56"  "57"  "58"  "59"  "60"  "61"  "62"  "63"  "64"  "65"  "66"  "67"  "68"  "69"  "70"  "71"  "72"  "73"  "74"  "75"  "76"  "77" 
# [27] "79"  "80"  "81"  "82"  "83"  "84"  "85"  "86"  "87"  "88"  "89"  "90"  "91"  "92"  "93"  "94"  "95"  "96"  "97"  "98"  "99"  "100" "102" "107" "114" "115"
# [53] "120" "122" "124" "127" "128" "134" "139" "143" "147" "150"
# 
# $`2`
#  [1] "53"  "78"  "101" "103" "104" "105" "106" "108" "109" "110" "111" "112" "113" "116" "117" "118" "119" "121" "123" "125" "126" "129" "130" "131" "132" "133"
# [27] "135" "136" "137" "138" "140" "141" "142" "144" "145" "146" "148" "149"
# 
# $`3`
#  [1] "1"  "2"  "3"  "4"  "5"  "6"  "7"  "8"  "9"  "10" "11" "12" "13" "14" "15" "16" "17" "18" "19" "20" "21" "22" "23" "24" "25" "26" "27" "28" "29" "30" "31" "32"
# [33] "33" "34" "35" "36" "37" "38" "39" "40" "41" "42" "43" "44" "45" "46" "47" "48" "49" "50"

相关问题