当前位置:网站首页>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)
边栏推荐
- C#基于当前时间,获取唯一识别号(ID)的方法
- MySQL stored procedure cursor traversal result set
- php 二维、多维 数组打乱顺序,PHP_php打乱数组二维数组多维数组的简单实例,php中的shuffle函数只能打乱一维
- Attribute acquisition method and operation notes of C # multidimensional array
- 基于 Openzeppelin 的可升级合约解决方案的注意事项
- The computer screen is black for no reason, and the brightness cannot be adjusted.
- Some problems encountered in introducing lvgl into esp32 Arduino
- Develop scalable contracts based on hardhat and openzeppelin (I)
- GGPLOT: HOW TO DISPLAY THE LAST VALUE OF EACH LINE AS LABEL
- Tiktok overseas tiktok: finalizing the final data security agreement with Biden government
猜你喜欢
excel表格中选中单元格出现十字带阴影的选中效果
RPA advanced (II) uipath application practice
Tdsql | difficult employment? Tencent cloud database micro authentication to help you
Develop scalable contracts based on hardhat and openzeppelin (I)
数字化转型挂帅复产复工,线上线下全融合重建商业逻辑
How to Easily Create Barplots with Error Bars in R
Principe du contrat évolutif - delegatecall
K-Means Clustering Visualization in R: Step By Step Guide
Data analysis - Matplotlib sample code
动态内存(进阶四)
随机推荐
What is the relationship between digital transformation of manufacturing industry and lean production
Bedtools tutorial
Map set assignment to database
[idea] use the plug-in to reverse generate code with one click
excel表格中选中单元格出现十字带阴影的选中效果
bedtools使用教程
R HISTOGRAM EXAMPLE QUICK REFERENCE
预言机链上链下调研
Attribute acquisition method and operation notes of C # multidimensional array
RPA advanced (II) uipath application practice
Visualization of chip SEQ data by deeptools
微信小程序利用百度api达成植物识别
BEAUTIFUL GGPLOT VENN DIAGRAM WITH R
Three transparent LED displays that were "crowded" in 2022
mysql链表数据存储查询排序问题
A sharp tool for exposing data inconsistencies -- a real-time verification system
Cluster Analysis in R Simplified and Enhanced
基于Hardhat编写合约测试用例
数据分析 - matplotlib示例代码
CMake交叉编译