【数模matlab】数据建模:主成分分析(PCA)

简介

PCA是一种属降维方法,将众多具有一定相关性的变量重组为一组新的相互无关的综合变量,可以用作降维或评价(建议不用,因为新综合变量很难解释)。此方法在实际运用中有一个难点,就是选择主成分后,需要注意主成分实际含义的解释(难点)。

PCA步骤

1、原始数据标准化处理
在这里插入图片描述
2、计算样本相关系数矩阵

3、计算相关系数矩阵的特征值以及相应的特征向量
在这里插入图片描述
4、选择主成分并写出表达式
根据贡献率选出主成分
5、计算主成分得分:样本数据*主成分特征向量
在这里插入图片描述
6、进一步分析
在这里插入图片描述

实现代码

% Read data from a file (e.g. excel) and place it in a matrix.
A=xlsread('Coporation_evaluation.xlsx', 'B2:I16');

% Transfer orginal data to standard data
a=size(A,1);   % Get the row number of A
b=size(A,2);   % Get the column number of A
for i=1:b
    SA(:,i)=(A(:,i)-mean(A(:,i)))/std(A(:,i));  % Matrix normalization
end

% Calculate correlation matrix of A.
CM=corrcoef(SA);

% Calculate eigenvectors and eigenvalues of correlation matrix.
[V, D]=eig(CM);

% Get the eigenvalue sequence according to descending and the corrosponding
% attribution rates and accumulation rates.
for j=1:b
    DS(j,1)=D(b+1-j, b+1-j);
end
for i=1:b
    DS(i,2)=DS(i,1)/sum(DS(:,1)); % 贡献率
    DS(i,3)=sum(DS(1:i,1))/sum(DS(:,1)); % 累计贡献率
end

% Calculate the numvber of principal components.
T=0.9;  % set the threshold value for evaluating information preservation level.
for K=1:b
    if DS(K,3)>=T
        Com_num=K;
        break;
    end
end

% Get the eigenvectors of the Com_num principal components
for j=1:Com_num
    PV(:,j)=V(:,b+1-j); % 与之前倒序排列的特征值相匹配,故需要倒序
end

% Calculate the new socres of the orginal items
new_score=SA*PV; 

for i=1:a
    total_score(i,2)=sum(new_score(i,:));
    total_score(i,1)=i;
end
new_score_s=sortrows(total_score,-2);

% Displays result reports
disp('特征值及贡献率:')
DS
disp('阀值T对应的主成分数与特征向量:')
Com_num
PV
disp('主成分分数:')
new_score
disp('主成分分数排序:')
new_score_s


易知第9家综合实力最强,第12家综合实力最弱

  • 2
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值