clc;clear;close all
disp('原始数据,不同预处理方法进行处理的RMSECV,RMSEP,训练集及预测集的R')
load UV
cal = calset(:,1:600);
caltar = calsettar;
for columm = 1:4;
dataname = ynames{columm};
disp(dataname);
%----------------------------因子数的确定--------------------------------
switch columm
case 1
maxrank = 8;
case 2
maxrank = 6;
case 3
maxrank = 7;
case 4
maxrank = 6;
end
[m,n] = size(cal);
%-----------------KS对数据划分,训练集2/3,预测集1/3---------------------
[model,test] = kenstone(cal,floor(2/3*m));
x_train = cal(model,:);
x_pred = cal(test,:);
y_train = caltar(model,columm);
y_pred = caltar(test,columm);
[m_train,n_train] = size(x_train);
%-------------------------------PLS------------------------------------
disp('偏最小二乘-PLS')
b = simpls(x_train,y_train,maxrank);
c = x_pred*b(:,maxrank);
[c_train,valpresses] = loocv(x_train,y_train,maxrank);
disp('RMSECV,RMSEP,训练集及预测集的R');
rmsecv_PLS = sqrt(valpresses./m_train);
rmsep_PLS = rms(c-y_pred);
r_train = corrcoef(c_train,y_train);
r_train = r_train(1,2);
r_PLS = corrcoef(c,y_pred);
r_PLS = r_PLS(1,2);
disp([rmsecv_PLS,rmsep_PLS,r_train,r_PLS]);
disp('回收率最大最小值');
recovery_PLS = 100*c./y_pred;
max_recovery_PLS(columm) = max(recovery_PLS);
min_recovery_PLS(columm) = min(recovery_PLS);
disp([max_recovery_PLS(columm),min_recovery_PLS(columm)]);
clear b c c_train valpresses r_train
%---------------------------------------------------------------------
ttt = 1;
for window = 3:2:40
disp(window);
disp('S-G平滑');
x_train_SG = sgdiff(x_train,2,window,2);
x_pred_SG = sgdiff(x_pred,2,window,2);
[p, q, w, b] = ch_pls_new(x_train_SG,y_train,maxrank);
c = ch_plspred(x_pred_SG, p, q, w, b,maxrank);
disp('RMSEP及R');
rmsep_SG(ttt) = rms(c-y_pred);
R_SG = corrcoef(c,y_pred);
r_SG(ttt) = R_SG(1,2);
disp([rmsep_SG,r_SG]);
disp('回收率最大最小值');
recovery_SG = 100*c./y_pred;
max_recovery_SG(ttt) = max(recovery_SG);
min_recovery_SG(ttt) = min(recovery_SG);
ttt = ttt + 1;
disp([max_recovery_SG,min_recovery_SG]);
end
text_size = 16;
figure;subplot(2,2,1);plot([3:2:40],rmsep_SG,'o-','LineWidth',2);set(gca,'fontsize',text_size);title(dataname,'fontsize',text_size+1);
xlabel('Window','fontsize',text_size);ylabel('RMSEP','fontsize',text_size);
subplot(2,2,2);plot([3:2:40],r_SG,'o-','LineWidth',2);set(gca,'fontsize',text_size);title(dataname,'fontsize',text_size+1);
xlabel('Window','fontsize',text_size);ylabel('R','fontsize',text_size);
subplot(2,2,3);plot([3:2:40],max_recovery_SG,'*-','LineWidth',2);set(gca,'fontsize',text_size);title(dataname,'fontsize',text_size+1);
xlabel('Window','fontsize',text_size);ylabel('Max-recovery','fontsize',text_size);
subplot(2,2,4);plot([3:2:40],min_recovery_SG,'*-','LineWidth',2);set(gca,'fontsize',text_size);title(dataname,'fontsize',text_size+1);
xlabel('Window','fontsize',text_size);ylabel('Min-recovery','fontsize',text_size);
end
评论0