偏最小二乘回归(PLS)的MATLAB实现

 
  
clc;
clear;
load('sample_alldata.mat');
sample=10000*sample_alldata(:,2:end-1);
wave_s=34;
wave_e=464;
data_train=sample(1:65,wave_s:wave_e);
data_predict=sample(66:end,wave_s:wave_e);

target_out=sample_alldata(1:65,end);%训练集
data_predict=data_predict/max(data_predict);%测试
predict_out=sample_alldata(66:end,end);
num=size(data_train,1);%训练集样本数
for i=1:num
  %数据标准化
  data_train(i,:)=zscore(data_train(i,:));
end

n=size(data_train,2);%自变量维度
m=size(target_out,2);%因变量维度

%for i=1:num-1
 %forj=1:num
  % [XL,YL,XS,YS,beta,PCTVAR,MSE]=plsregress(data_train,target_out,i);
%end
%end

handleofwaitbar=waitbar(0);%设置进度条便于观察
%交叉验证
SS=[];
PRESS=[];
Q=[];
mse=[];
for h=2:num-2 %分别验证选取不同的成分数时,成分数不能多于样本数
 ncomp=h;%成分数
[XL,YL,XS,YS,beta,PCTVAR,MSE]=plsregress(data_train,target_out,ncomp-1);%所有的样本建模,但成分数少一(h

你可能感兴趣的:(统计建模,机器学习,模式识别)