当前位置:网站首页>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)
边栏推荐
- sql left join 主表限制条件写在on后面和写在where后面的区别
- tidb-dm报警DM_sync_process_exists_with_error排查
- MySQL linked list data storage query sorting problem
- PYQT5+openCV项目实战:微循环仪图片、视频记录和人工对比软件(附源码)
- PHP tea sales and shopping online store
- ESP32音频框架 ESP-ADF 添加按键外设流程代码跟踪
- Order by注入
- Rest (XOR) position and thinking
- C#基于当前时间,获取唯一识别号(ID)的方法
- 抖音海外版TikTok:正与拜登政府敲定最终数据安全协议
猜你喜欢

A white hole formed by antineutrons produced by particle accelerators

HOW TO CREATE AN INTERACTIVE CORRELATION MATRIX HEATMAP IN R

ImportError: cannot import name ‘Digraph‘ from ‘graphviz‘

抖音海外版TikTok:正与拜登政府敲定最终数据安全协议

Cluster Analysis in R Simplified and Enhanced

Is the Ren domain name valuable? Is it worth investing? What is the application scope of Ren domain name?

Basic usage of MySQL in centos8

Seriation in R: How to Optimally Order Objects in a Data Matrice

mmrotate旋转目标检测框架使用记录

GGPlot Examples Best Reference
随机推荐
Tick Data and Resampling
在连接mysql数据库的时候一直报错
Tick Data and Resampling
PLC-Recorder快速监控多个PLC位的技巧
从攻击面视角,看信创零信任方案实践
Verilog and VHDL signed and unsigned number correlation operations
制造业数字化转型和精益生产什么关系
GGPlot Examples Best Reference
GGPUBR: HOW TO ADD ADJUSTED P-VALUES TO A MULTI-PANEL GGPLOT
ros缺少xacro的包
Multi line display and single line display of tqdm
SSRF
webauthn——官方开发文档
LVM operation
Order by注入
Precautions for scalable contract solution based on openzeppelin
II Stm32f407 chip GPIO programming, register operation, library function operation and bit segment operation
Thanos Receiver
【IDEA】使用插件一键逆向生成代码
基于Hardhat和Openzeppelin开发可升级合约(一)
