捕获 K 个聚类

R 中的聚类分析

Dmitriy Gorenshteyn

Lead Data Scientist, Memorial Sloan Kettering Cancer Center

R 中的聚类分析

R 中的聚类分析

R 中的聚类分析

R 中的聚类分析

R 中的聚类分析

R 中的聚类分析

R 中的聚类分析

R 中的聚类分析

R 中的聚类分析

R 中的聚类分析

R 中的聚类分析

R 中的层次聚类

print(players)
      x     y 
   <dbl> <dbl>
1    -1     1 
2    -2    -3 
3     8     6 
4     7    -8 
5   -12     8 
6   -15     0
dist_players <- dist(players, method = 'euclidean')

hc_players <- hclust(dist_players, method = 'complete')
R 中的聚类分析

提取 K 个聚类

cluster_assignments <- cutree(hc_players, k = 2)
print(cluster_assignments)
[1] 1 1 1 1 2 2
library(dplyr)
players_clustered <- mutate(players, cluster = cluster_assignments)
print(players_clustered)
      x     y cluster
  <dbl> <dbl>   <int>
1    -1     1       1
2    -2    -3       1
3     8     6       1
4     7    -8       1
5   -12     8       2
6   -15     0       2
R 中的聚类分析

可视化 K 个聚类

library(ggplot2)
ggplot(players_clustered, aes(x = x, y = y, color = factor(cluster))) +
  geom_point()

R 中的聚类分析

开始练习!

R 中的聚类分析

Preparing Video For Download...