当前位置:网站首页>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)
边栏推荐
- Amazon cloud technology community builder application window opens
- 行业的分析
- Installation of ROS gazebo related packages
- Thesis translation: 2022_ PACDNN: A phase-aware composite deep neural network for speech enhancement
- Seriation in R: How to Optimally Order Objects in a Data Matrice
- Wechat applet uses Baidu API to achieve plant recognition
- Webauthn - official development document
- 电脑无缘无故黑屏,无法调节亮度。
- [multithreading] the main thread waits for the sub thread to finish executing, and records the way to execute and obtain the execution result (with annotated code and no pit)
- QT meter custom control
猜你喜欢

JS -- take a number randomly from the array every call, and it cannot be the same as the last time

Three transparent LED displays that were "crowded" in 2022

R HISTOGRAM EXAMPLE QUICK REFERENCE

How to Easily Create Barplots with Error Bars in R

PgSQL string is converted to array and associated with other tables, which are displayed in the original order after matching and splicing

pgsql 字符串转数组关联其他表,匹配 拼接后原顺序展示

Never forget, there will be echoes | hanging mirror sincerely invites you to participate in the opensca user award research

Summary of data export methods in powerbi

Attribute acquisition method and operation notes of C # multidimensional array

Webauthn - official development document
随机推荐
QT meter custom control
PYQT5+openCV项目实战:微循环仪图片、视频记录和人工对比软件(附源码)
Amazon cloud technology community builder application window opens
2022年遭“挤爆”的三款透明LED显示屏
The position of the first underline selected by the vant tabs component is abnormal
MySQL stored procedure cursor traversal result set
How to Easily Create Barplots with Error Bars in R
【多线程】主线程等待子线程执行完毕在执行并获取执行结果的方式记录(有注解代码无坑)
pgsql 字符串转数组关联其他表,匹配 拼接后原顺序展示
基于 Openzeppelin 的可升级合约解决方案的注意事项
Webauthn - official development document
Solve the problem of data blank in the quick sliding page of the uniapp list
YYGH-BUG-05
通讯录的实现(文件版本)
Redis exceeds the maximum memory error oom command not allowed when used memory & gt; ' maxmemory'
Cmake cross compilation
Liftover for genome coordinate conversion
Digital transformation takes the lead to resume production and work, and online and offline full integration rebuilds business logic
Compilation errors and printout garbled problems caused by Chinese content in vs2019 code
Is it safe to open a stock account through the QR code of the securities manager? Or is it safe to open an account in a securities company?
