Principal Component Analysis PCA Algorithm

Principal Components Analysis

This covariance matrix is ​​an nXn and is a symmetric matrix, so there will be n eigenvalues ​​λ and eigenvectors v, and each eigenvector is also n-dimensional. The eigenvector v in the first row corresponds to the eigenvalue λ1.

D(yk): Indicates the variance of the principal component yk. The larger the variance, the more information it carries.

Table 1 Data on the development of general higher education in various regions of my country 

The covariance matrix of the standardized data is the correlation coefficient matrix.

code: 

clc,clear
load gj.txt %把原始数据保存在纯文本gj.txt中
gj=zscore(gj);%数据标准化
r=corrcoef(gj);%计算相关系数矩阵(协方差矩阵)
%下面利用相关系数矩阵进行主成分分析,vec1的列为r的特征向量,即主成分的系数
[vec1,lamda,rate]=pcacov(r);%lamda为r的特征值,rate为各个主成分的贡献值
num=4;%num为选取的主成分的个数
df=gj*vec1(:,1:num);%计算前四个主成分的得分
tf=df*rate(1:num)/100;%计算综合得分
[std,ind]=sort(tf,'descend');%把得分按照从高到低的次序排序,std就是得分,ind是原来的标号

Guess you like

Origin blog.csdn.net/m0_58086930/article/details/132023673
Recommended