matlab pls rmsecv,偏最小二乘法PLS回归NIPALS算法及Matlab程序及例子.doc

偏最小二乘法PLS回归NIPALS算法及Matlab程序及例子

偏最小二乘法PLS回归NIPALS算法的Matlab程序及例子

function [T,P,W,Wstar,U,b,C,B_pls,...??????? Bpls_star,Xori_rec,Yori_rec,...??????? R2_X,R2_Y]=PLS_nipals(X,Y,nfactor)% USAGE: [T,P,W,Wstar,U,b,C,Bpls,Bpls_star,Xhat,Yhat,R2X,R2Y]=PLS_nipals(X,Y,nfact)% PLS regression NIPALS algorithm PLS回归NIPALS算法% Compute the PLS regression coefficients PLS回归系数的计算% X=T*P' Y=T*B*C'=X*Bpls X and Y being Z-scores%????????????????????????? B=diag(b)%??? Y=X*Bpls_star with X being augmented with a col of ones%?????????????????????? and Y and X having their original units% T'*T=I (NB normalization <> SAS)% W'*W=I%% Test for PLS regression% Herve Abdi November 2002/rev November 2004%%% Version with T, W, and C being unit normalized% U, P are not% nfact=number of latent variables to keep 保持潜在变量的数量% default = rank(X)X_ori=X;Y_ori=Y;if exist('nfactor')~=1;nfactor=rank(X);endM_X=mean(X);M_Y=mean(Y);S_X=std(X);S_Y=std(Y);X=zscore(X);Y=zscore(Y);[nn,np]=size(X) ;[n,nq]=size(Y) ;if nn~= n;??? error(['Incompatible # of rows for X and Y']);end% Precision for convergenceepsilon=eps;% # of components kepts% Initialistion% The Y setU=zeros(n,nfactor);C=zeros(nq,nfactor);% The X setT=zeros(n,nfactor);P=zeros(np,nfactor);W=zeros(np,nfactor);b=zeros(1,nfactor);R2_X=zeros(1,nfactor);R2_Y=zeros(1,nfactor);

Xres=X;Yres=Y;SS_X=sum(sum(X.^2));SS_Y=sum(sum(Y.^2));for l=1:nfactor????t=normaliz(Yres(:,1));t0=normaliz(rand(n,1)*10);u=t;nstep=0;maxstep=100;while ( ( (t0-t)'*(t0-t) > epsilon/2) & (nstep < maxstep));??? nstep=nstep+1;?? disp(['Latent Variable #',int2str(l),' Iteration #:',int2str(nstep)])?? t0=t;?? w=normaliz(Xres'*u);?? t=normaliz(Xres*w);?? % t=Xres*w;?? c=normaliz(Yres'*t);?? u=Yres*c;end;disp(['Latent Variable #',int2str(l),', convergence reached at step ',...??? int2str(nstep)]);%X loadingsp=Xres'*t;% b coefb_l=((t'*t)^(-1))*(u'*t);b_1=u'*t;% Store in matricesb(l)=b_l;P(:,l)=p;W(:,l)=w;T(:,l)=t;U(:,l)=u;C(:,l)=c;% deflation of X a

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值