DaveM@3: function features = rfFeatureSelection(data, labels, numFeatures, iterMethod, numTrees) DaveM@3: %% rfFeatureSelection(data, labels, numFeatures, iterMethod, numTrees) DaveM@3: % DaveM@3: % DaveM@3: % DaveM@3: % DaveM@3: DaveM@3: if(length(labels) ~= size(data,1)) DaveM@3: error('labels and data do not match up'); DaveM@3: end DaveM@3: DaveM@3: if(nargin < 2) DaveM@3: error('must pass data and labels into function') DaveM@3: end DaveM@3: if(nargin < 3) DaveM@3: numFeatures = 5; DaveM@3: end DaveM@3: if(nargin < 4) DaveM@3: iterMethod = 'onePass'; DaveM@3: end DaveM@3: if(nargin < 5) DaveM@3: numTrees = 200; DaveM@3: end DaveM@3: DaveM@3: DaveM@3: options = statset('UseParallel', true); DaveM@3: b = TreeBagger(numTrees, data, labels,'OOBVarImp','On',... DaveM@3: 'SampleWithReplacement', 'Off','FBoot', 0.632,'Options', options); DaveM@3: [FI,I] = sort(b.OOBPermutedVarDeltaError,'descend'); DaveM@3: features = I; DaveM@3: DaveM@3: if(strcmp(iterMethod,'onePass')) DaveM@3: disp('cut') DaveM@3: features = features(1:numFeatures); DaveM@3: elseif(strcmp(iterMethod,'cut10')) DaveM@3: disp('cut10') DaveM@3: cutSize = max(floor(length(features)/10),1); DaveM@3: features = features(1:end-cutSize); DaveM@3: data = data(:,I); DaveM@3: features = rfFeatureSelection(data, labels, numFeatures, iterMethod, numTrees); DaveM@3: elseif(strcmp(iterMethod,'cut5')) DaveM@3: disp('cut5') DaveM@3: cutSize = max(floor(length(features)/20),1); DaveM@3: features = features(1:end-cutSize); DaveM@3: data = data(:,I); DaveM@3: features = rfFeatureSelection(data, labels, numFeatures, iterMethod, numTrees); DaveM@3: end DaveM@3: end