pcpred.m

来自「用VC++编写的遗传算法源程序」· M 代码 · 共 44 行

M
44
字号
function [pred,impact]=pcrpred(x,c,tx,ty,n)
%
% predicts system output given the coefficients
% of the principal components, and the number
% of components to include.
%
% MUST BE GIVEN SCALED DATA
%

%
% Build correct sized set of coefficients
%
cs=c(:,1:n);

%
% calculate the principal components
%
pcs=tx*cs;
size(pcs);
%
% calculate the regression vector
%
a=inv(pcs'*pcs)*pcs'*ty;

%
% Calculate the output
%
pred=x*cs;

pred=pred*a;

%
% Now calculate the impact of each variable
% (ie its overall regression vector
%
[D L]=size(x);
impact=zeros(1,L);

for i = 1:L
	for j = 1:n
		impact(i)=impact(i)+cs(i,j)*a(j);
	end
end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?