光谱在食品检测等领域得到广泛应用,然而,光谱数据通常包含大量波段,存在信息冗余和多重共线性等问题,直接使用原始光谱数据建模易导致过拟合和模型泛化能力差。因此,有必要在建模之前,从海量波段中筛选出最相关的特征波段,降低数据维度。
竞争适应性重加权采样(Competitive Adaptive Reweighted Sampling, CARS)是一种有效的光谱特征波段选择算法。其基本思想是通过蒙特卡洛采样和指数衰减函数,自适应地调整各波段的选择概率,最终选出对建模性能贡献最大的最优波段组合。
load 'data.mat'; % example data
Xtrain = train;
Xtest = test;
ytrain = trainlabel;
ytest = testlabel;
Amax=20; % Maximal allowed number of PLS components
method='center'; % data pretreatment (internal use)
N=500; % number of Mnote Carlo samplings.
MCCV=plsmccv(Xtrain,ytrain,Amax,method,N); % run MCCV
plot(MCCV.RMSECV,'b-o','linewidth',2); % plot RMSECV values at each number of latent variables(LVs)
xlabel('NO. of LVs','FontSize',20);
ylabel('RMSECV','FontSize',20);
% Variable selection using the CARS method. 'autos