当前位置:网站首页>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)
边栏推荐
- 【云原生】2.5 Kubernetes 核心实战(下)
- bedtools使用教程
- Resources reads 2D texture and converts it to PNG format
- From the perspective of attack surface, see the practice of zero trust scheme of Xinchuang
- R HISTOGRAM EXAMPLE QUICK REFERENCE
- Compilation errors and printout garbled problems caused by Chinese content in vs2019 code
- Wechat applet uses Baidu API to achieve plant recognition
- Amazon cloud technology community builder application window opens
- Cluster Analysis in R Simplified and Enhanced
- ROS lacks xacro package
猜你喜欢
揭露数据不一致的利器 —— 实时核对系统
从攻击面视角,看信创零信任方案实践
Develop scalable contracts based on hardhat and openzeppelin (II)
可升级合约的原理-DelegateCall
Thanos Receiver
excel表格中选中单元格出现十字带阴影的选中效果
[idea] use the plug-in to reverse generate code with one click
PowerBI中导出数据方法汇总
tidb-dm报警DM_sync_process_exists_with_error排查
How to Create a Nice Box and Whisker Plot in R
随机推荐
Is it safe to open a stock account online? I'm a novice, please guide me
map集合赋值到数据库
PLC-Recorder快速监控多个PLC位的技巧
spritejs
spritejs
ESP32存储配网信息+LED显示配网状态+按键清除配网信息(附源码)
亚马逊云科技 Community Builder 申请窗口开启
mysql 基本语句
What are the methods of adding elements to arrays in JS
How to Visualize Missing Data in R using a Heatmap
Cluster Analysis in R Simplified and Enhanced
Basic usage of MySQL in centos8
R HISTOGRAM EXAMPLE QUICK REFERENCE
ren域名有价值吗?值不值得投资?ren域名的应用范围有哪些?
Webauthn - official development document
原生方法合并word
Tiktok overseas tiktok: finalizing the final data security agreement with Biden government
What is the relationship between digital transformation of manufacturing industry and lean production
C#基于当前时间,获取唯一识别号(ID)的方法
基于 Openzeppelin 的可升级合约解决方案的注意事项