NCA feature selection method

14 次查看(过去 30 天)
Alaa Almazroey
Alaa Almazroey 2019-9-11
评论: Alexis 2020-9-29
i tried to use NCA feature selection method to select the most relitive features from 16483 features, but i always got all features because the bestlambda and bestloss are always 0. how can work in this problem.
another question how can i set the lambdavals, is there a rule or something for linspace () parameter? as well how can i select the best value for 'tol' ?
cvx=cvpartition(size(Features,1),'kfold',5);
numvalidsets = cvx.NumTestSets;
n = cvx.TrainSize(1);
lambdavals=(linspace(0,20,20)./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',1,'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);
tol = 0.55;
selidx = find(nca.FeatureWeights > tol*max(1,max(nca.FeatureWeights)))
Best_Features_train = XTrain(:,selidx);
  1 个评论
Alexis
Alexis 2020-9-29
I have this same problem. Without an error message or warning it's not clear to me where to start. I have 14 features and over 5,000 observations.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Fit Postprocessing 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by