当前位置:网站首页>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)
边栏推荐
- ESP32存储配网信息+LED显示配网状态+按键清除配网信息(附源码)
- Native method merge word
- R HISTOGRAM EXAMPLE QUICK REFERENCE
- Never forget, there will be echoes | hanging mirror sincerely invites you to participate in the opensca user award research
- Introduction to interface debugging tools
- QT获取某个日期是第几周
- 原生方法合并word
- Is the stock account given by qiniu business school safe? Can I open an account?
- 基于Hardhat编写合约测试用例
- Bedtools tutorial
猜你喜欢

预言机链上链下调研

Verilog 和VHDL有符号数和无符号数相关运算
![[idea] use the plug-in to reverse generate code with one click](/img/b0/00375e61af764a77ea0150bf4f6d9d.png)
[idea] use the plug-in to reverse generate code with one click

Cluster Analysis in R Simplified and Enhanced

What is the relationship between digital transformation of manufacturing industry and lean production

Importerror: impossible d'importer le nom « graph» de « graphviz»

From the perspective of attack surface, see the practice of zero trust scheme of Xinchuang

Tick Data and Resampling

A white hole formed by antineutrons produced by particle accelerators

Mongodb learning and sorting (condition operator, $type operator, limit() method, skip() method and sort() method)
随机推荐
PKG package manager usage instance in FreeBSD
2022年遭“挤爆”的三款透明LED显示屏
Cluster Analysis in R Simplified and Enhanced
Multi line display and single line display of tqdm
MySQL comparison operator in problem solving
SSRF
PHP tea sales and shopping online store
MySQL比较运算符IN问题求解
How to Visualize Missing Data in R using a Heatmap
Wechat applet uses Baidu API to achieve plant recognition
ImportError: cannot import name ‘Digraph‘ from ‘graphviz‘
MTK full dump grab
Mongodb learning and sorting (condition operator, $type operator, limit() method, skip() method and sort() method)
QT获取某个日期是第几周
Rest (XOR) position and thinking
GGPlot Examples Best Reference
Resources reads 2D texture and converts it to PNG format
Cluster Analysis in R Simplified and Enhanced
【IDEA】使用插件一键逆向生成代码
Precautions for scalable contract solution based on openzeppelin
