1 function [iFeatSelected, train_data, test_data] =
feature_sel_module(train_data, test_data, labelsTrain, parameters)
2 %feature selection module
4 train_data(isnan(train_data)) = 0;
5 if ~isfield(parameters,
'pca_tresh')
8 pca_tresh = parameters.pca_tresh;
10 if ~isfield(parameters, 'is_regression')
11 parameters.is_regression = 0;
14 nbFeatures = size(train_data,2);
15 switch parameters.featSelection
17 c = cvpartition(labelsTrain,'k',10);
18 opts = statset('display','iter');
19 classifier = 'diaglinear';
20 priorP = ones(1,parameters.nbClasses)/parameters.nbClasses;
21 fun = @(XT,yT,Xt,yt)...
22 (((sum((yt==2)&(classify(Xt,XT,yT,classifier,priorP)==1))/sum(yt==2))*10+(sum((yt==1)&(classify(Xt,XT,yT,classifier,priorP)==2))/sum(yt==1)))/11);
23 [inmodel, ~]= sequentialfs(fun,train_data,labelsTrain,'cv',c,'direction','forward', 'options',opts); %
24 iFeatSelected = find(inmodel);
26 [listFeatures,FC] =
fisherCrit(train_data,labelsTrain, parameters.nbClasses);
27 FisherThreshold = 0.3;
28 iFeatSelected = listFeatures(FC>FisherThreshold);
29 if length(iFeatSelected) < 3
30 iFeatSelected = listFeatures(1:3);
34 iFeatSelected = 1:size(train_data,2);
36 if isempty(iFeatSelected)
37 iFeatSelected = 1:nbFeatures;
39 train_data = train_data(:,iFeatSelected);
40 test_data = test_data(:,iFeatSelected);