首页 > 其他分享 >PCA图_绘图(一)

PCA图_绘图(一)

时间:2023-03-05 23:12:37浏览次数:41  
标签:iris FactoMineR library factoextra 绘图 PCA data

使用的R包:FactoMineR factoextra

FactoMineR提供PCA算法以及(原始)结果;factoextra则extract and visualize the output

Principal Component Analysis (PCA), which is used to summarize the
information contained in a continuous (i.e, quantitative)
multivariate data by reducing the dimensionality of the data
without loosing important information.

library("FactoMineR")
library("factoextra")
data("decathlon2")
df <- decathlon2[1:23, 1:10]  # loading data

pcaResult = PCA(df,  graph = FALSE)  # PCA来自FactoMineR,只要result而不graph

get_eig(pcaResult)  # eigenvalue 特征值
# get_eigenvalue(pcaResult)  
# get_pca(pcaResult)
# fviz_screeplot(pcaResult, addlabels = TRUE, ylim = c(0, 50))

var = get_pca_var(pcaResult)
# var
# head(var$coord)
# head(var$contrib)
fviz_pca_var(pcaResult, col.var = "black")
# Control variable colors using their contributions
fviz_pca_var(pcaResult, col.var="contrib",
             gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
             repel = TRUE # Avoid text overlapping
             )

ind = get_pca_ind(pcaResult)
# ind
# head(ind$coord)  
fviz_pca_ind(pcaResult, col.ind = "cos2", 
             gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
             repel = TRUE # Avoid text overlapping (slow if many points)
             )

# Biplot of individuals and variables
fviz_pca_biplot(pcaResult, repel = TRUE)  

所以该怎么理解variables和individuals…

pcaResult

换熟悉的iris数据集看看

# Compute PCA on the iris data set
# The variable Species (index = 5) is removed
# before PCA analysis
iris.pca <- PCA(iris[,-5], graph = FALSE)

# Visualize
# Use habillage to specify groups for coloring
fviz_pca_ind(iris.pca,
             label = "none", # hide individual labels
             habillage = iris$Species, # color by groups
             palette = c("#00AFBB", "#E7B800", "#FC4E07"),
             addEllipses = TRUE # Concentration ellipses
             )

参考资料

FactoMineR: Exploratory Multivariate Data Analysis with R

factoextra : Extract and Visualize the Results of Multivariate Data Analyses

标签:iris,FactoMineR,library,factoextra,绘图,PCA,data
From: https://www.cnblogs.com/yknNewbie/p/17182105.html

相关文章

  • php之Opcache深入理解
    PHP项目中,尤其是在高并发大流量的场景中,如何提升PHP的响应时间,是一项十分重要的工作。而Opcache又是优化PHP性能不可缺失的组件,尤其是应用了PHP框架的项目中,作用更是明显。......
  • 总算能生产出能看的了AI绘图
      ......
  • WINFORM + C# GDI+编程实现Photoshop, Illustrator类似绘图工具箱
    先看效果:其中,比较麻烦的是颜色选取工具,如下图: 要求点击上图颜色区域均可弹出如下图所示的颜色选取器对话框,其中:1、左侧左上角为对象填充,点击右侧右下角为边框颜色选择,左侧......
  • python基本绘图函数
    1.plot绘制线型图plot是python中最基本的绘制二维线性折线图的函数基本使用方式:plt.plot(x,y,s)代码实现:importmatplotlib.pyplotaspltimportnumpyasnpimportpa......
  • python基本绘图函数学习
    1.plot绘制线型图plot是python中最基本的绘制二维线性折线图的函数基本使用方式:plt.plot(x,y,s)代码实现:importmatplotlib.pyplotaspltimportnumpyasnpimport......
  • 大数据挖掘-python基本绘图函数学习
    1-plot绘制线型图plot是python中最基本的绘制二维线性折线图的函数基本使用方式:plt.plot(x,y,s)代码实现:importmatplotlib.pyplotaspltimportnumpyasnpimport......
  • Python用于数据绘图
    importpandasaspdimportmatplotlib.pyplotasplt#导入绘图包plt.rcParams['font.sans-serif']=['SimHei']#解决中文显示问题plt.rcParams[......
  • Python绘图
    1.二维绘图a.一维数据集用Numpyndarray作为数据传入ply1.importnumpyasnpimportmatplotlibasmplimportmatplotlib.pyplotaspltnp.random.seed(1000)y=np.ra......
  • python数据分析绘图
    importpandasaspdcatering_sale='D:\计算机网络\catering_sale.xls'data=pd.read_excel(catering_sale,index_col='日期')print(data.describe())    ......
  • python绘图函数
    1.plot绘制线型图importmatplotlib.pyplotaspltimportnumpyasnpimportpandasaspdplt.rcParams['font.sans-serif']=['SimHei']plt.rcParams['axes.unicod......