NCA feature selection method

by user259665   Last Updated September 12, 2019 00:19 AM

I am using NCA feature selection method with five-fold cross-validation to select the best features my question is how to choose the best value of 'tol' variable? and for lambdavals??

cvx=cvpartition(size(Features,1),'kfold',5);
numvalidsets = cvx.NumTestSets;
n = cvx.TrainSize(1);
lambdavals=(linspace(0,11,11))./n;
lossvals = zeros(length(lambdavals),numvalidsets);
for w = 1:length(lambdavals)
     for p =1:numvalidsets
         train=1;
         test=1;
         indextrain=training(cvx,p);
         for i=1:size(Features,1)
             if indextrain(i)==1
                 XTrain(train,:)=Features(i,:);
                 YTrain(train)=label(i);
                 train=train+1;
             else
                 XTest(test,:)=Features(i,:);
                 YTest(test)=label(i);
                 test=test+1;
             end
         end
         TrainData= XTrain,YTrain;
         TestData =XTest,YTest;
         nca = fscnca(XTrain,YTrain,'FitMethod','exact', ...
             'Solver','sgd','Lambda',lambdavals(w), ...
              'IterationLimit',5,'Standardize',true);

        lossvals(w,p) = loss(nca,XTest,YTest,'LossFunction','classiferror');
     end
end
 %%
meanloss = mean(lossvals,2);
 [~,idx] = min(meanloss)% Find the index
bestlambda = lambdavals(idx) % Find the best lambda value
bestloss = meanloss(idx)
nca = fscnca(XTrain,YTrain,'FitMethod','exact','Solver','sgd',...
    'Lambda',bestlambda,'Standardize',true,'Verbose',1);
total    = 0.05; %??????
selidx = find(nca.FeatureWeights > total*max(1,max(nca.FeatureWeights)))


Related Questions




Choosing best training-validation split?

Updated February 18, 2018 04:19 AM

Validating a neural network

Updated August 07, 2019 21:19 PM

How to validate an ANN model?

Updated June 13, 2017 23:19 PM