Fit a PLS model to the centered data[Xfactors,Yfactors,Core,B] = npls(Xcalm,Ycalm,7);
Convert the parameters to scores and loadings[T,Wj,Wk] = fac2let(Xfactors);
[U,Q] = fac2let(Yfactors);
Use standard plots to evaluate the model.
Spectral score plot plot(T(:,1),T(:,2),'o')
for i = 1:size(T,1)
text(T(i,1),T(i,2),num2str(i))
end
title('SCORE PLOT')
xlabel('Score 1')
ylabel('Score 2')
T/U score plotfor j = 1:4
subplot(2,2,j)
plot(T(:,j),U(:,j),'o')
for i = 1:size(T,1)
text(T(i,j),U(i,j),num2str(i))
endtitle('T/U PLOT')
xlabel('Score 1')
ylabel('Score 1')
end
Loading plot plot(EmAx,Wj(:,1:4))
title('Emission loading plot')
xlabel('Wavelength/nm')
ylabel('Loading')
Determine the optimal number of componentsYnpls=[];
RMSEP=[];
for i=1:7
yp=npred(Xtestm,i,Xfactors,Yfactors,Core,B)+mean(ColorCal);
Ynpls=[Ynpls yp];
RMSEP=[RMSEP sqrt(mean( (yp-ColorVal)'*(yp-ColorVal) ))];
end
plot([1:7],RMSEP)
title('SCREE PLOT')
xlabel('Number of components')
ylabel ('RMSEP')
plot(ColorCal,Ynpls(:,OptNumb),'o')
where OptNumb
is the number you’ve determined as the optimal number of components (minimal RMSEP).
ylabel ('Predicted')
xlabel ('Reference')