当前位置:网站首页>K-Means Clustering Visualization in R: Step By Step Guide
K-Means Clustering Visualization in R: Step By Step Guide
2022-07-02 11:49:00 【Xiaoyu 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)
边栏推荐
- 基于Hardhat和Openzeppelin开发可升级合约(一)
- Basic usage of MySQL in centos8
- Is it safe to open a stock account online? I'm a novice, please guide me
- 在连接mysql数据库的时候一直报错
- 多文件程序X32dbg动态调试
- Cmake cross compilation
- Principe du contrat évolutif - delegatecall
- YYGH-10-微信支付
- The selected cells in Excel form have the selection effect of cross shading
- File operation (detailed!)
猜你喜欢

Tdsql | difficult employment? Tencent cloud database micro authentication to help you

CTF record

Esp32 audio frame esp-adf add key peripheral process code tracking

念念不忘,必有回响 | 悬镜诚邀您参与OpenSCA用户有奖调研

Thesis translation: 2022_ PACDNN: A phase-aware composite deep neural network for speech enhancement

How to Easily Create Barplots with Error Bars in R

6. Introduce you to LED soft film screen. LED soft film screen size | price | installation | application

Always report errors when connecting to MySQL database

Map set assignment to database

K-Means Clustering Visualization in R: Step By Step Guide
随机推荐
Precautions for scalable contract solution based on openzeppelin
[visual studio 2019] create MFC desktop program (install MFC development components | create MFC application | edit MFC application window | add click event for button | Modify button text | open appl
Skills of PLC recorder in quickly monitoring multiple PLC bits
Redis exceeds the maximum memory error oom command not allowed when used memory & gt; ' maxmemory'
Resources reads 2D texture and converts it to PNG format
Cmake cross compilation
pgsql 字符串转数组关联其他表,匹配 拼接后原顺序展示
MySQL basic statement
Eight sorting summaries
C#多维数组的属性获取方法及操作注意
行业的分析
ESP32存储配网信息+LED显示配网状态+按键清除配网信息(附源码)
PHP query distance according to longitude and latitude
Compilation errors and printout garbled problems caused by Chinese content in vs2019 code
Dynamic memory (advanced 4)
QT meter custom control
Implementation of address book (file version)
通讯录的实现(文件版本)
GGPlot Examples Best Reference
Order by注入