当前位置:网站首页>K-Means Clustering Visualization in R: Step By Step Guide
K-Means Clustering Visualization in R: Step By Step Guide
2022-07-02 09:41:00 【小宇2022】
library(ggpubr)
library(factoextra)
data("iris")
df <- iris
head(df, 3)
# Compute k-means with k = 3
set.seed(123)
res.km <- kmeans(scale(df[, -5]), 3, nstart = 25)
# K-means clusters showing the group of each individuals
res.km$cluster
fviz_cluster(res.km, data = df[, -5],
palette = c("#2E9FDF", "#00AFBB", "#E7B800"),
geom = "point",
ellipse.type = "convex",
ggtheme = theme_bw()
)
library(ggpubr)
library(factoextra)
data("iris")
df <- iris
head(df, 3)
# Compute k-means with k = 3
set.seed(123)
# Dimension reduction using PCA
res.pca <- prcomp(df[, -5], scale = TRUE)
# Coordinates of individuals
ind.coord <- as.data.frame(get_pca_ind(res.pca)$coord)
# Add clusters obtained using the K-means algorithm
ind.coord$cluster <- factor(res.km$cluster)
# Add Species groups from the original data sett
ind.coord$Species <- df$Species
# Data inspection
head(ind.coord)
# Percentage of variance explained by dimensions
eigenvalue <- round(get_eigenvalue(res.pca), 1)
variance.percent <- eigenvalue$variance.percent
head(eigenvalue)
ggscatter(
ind.coord, x = "Dim.1", y = "Dim.2",
color = "cluster", palette = "npg", ellipse = TRUE, ellipse.type = "convex",
shape = "Species", size = 1.5, legend = "right", ggtheme = theme_bw(),
xlab = paste0("Dim 1 (", variance.percent[1], "% )" ),
ylab = paste0("Dim 2 (", variance.percent[2], "% )" )
) +
stat_mean(aes(color = cluster), size = 4)
边栏推荐
- 基于 Openzeppelin 的可升级合约解决方案的注意事项
- 从ros1到ros2配置的一些东西
- On April 17, 2022, the five heart matchmaker team received double good news
- Homer forecast motif
- LVM operation
- C#基于当前时间,获取唯一识别号(ID)的方法
- Tidb DM alarm DM_ sync_ process_ exists_ with_ Error troubleshooting
- ASTParser 解析含有emum 枚举方法的类文件的踩坑记
- 预言机链上链下调研
- Webauthn - official development document
猜你喜欢
Webauthn - official development document
ESP32音频框架 ESP-ADF 添加按键外设流程代码跟踪
八大排序汇总
A sharp tool for exposing data inconsistencies -- a real-time verification system
CentOS8之mysql基本用法
PLC-Recorder快速监控多个PLC位的技巧
ren域名有价值吗?值不值得投资?ren域名的应用范围有哪些?
Tdsql | difficult employment? Tencent cloud database micro authentication to help you
Thanos Receiver
Tick Data and Resampling
随机推荐
数字化转型挂帅复产复工,线上线下全融合重建商业逻辑
ros gazebo相关包的安装
ren域名有价值吗?值不值得投资?ren域名的应用范围有哪些?
Attribute acquisition method and operation notes of C # multidimensional array
mysql 基本语句
QT获取某个日期是第几周
Digital transformation takes the lead to resume production and work, and online and offline full integration rebuilds business logic
sql left join 主表限制条件写在on后面和写在where后面的区别
原生方法合并word
PLC-Recorder快速监控多个PLC位的技巧
String (Analog
CTF record
微信小程序利用百度api达成植物识别
Compilation errors and printout garbled problems caused by Chinese content in vs2019 code
Homer forecast motif
Liftover for genome coordinate conversion
C#多维数组的属性获取方法及操作注意
6方面带你认识LED软膜屏 LED软膜屏尺寸|价格|安装|应用
A sharp tool for exposing data inconsistencies -- a real-time verification system
Principe du contrat évolutif - delegatecall