forked from viggin/yan-prtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathftSel_single.m
37 lines (31 loc) · 1.1 KB
/
ftSel_single.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function [ftRank,ftScore] = ftSel_single(ft,target,param)
%Feature ranking based on each single feature's prediction accuracy
% FT : sample matrix, each row is a sample.
% TARGET : a column vector, depend on the wrapper prediction algorithm
% used.
% PARAM: struct of parameters. The beginning part of this code (before
% defParam) explains each parameter, and also sets the default parameters.
% You can change parameter p to x by setting PARAM.p = x. For parameters
% that are not set, default values will be used.
% Return:
% FTRANK: rank of the features (most important first)
% FTSCORE: the accuracy of features corresponding to FTRANK.
%
% Ke YAN, 2016, Tsinghua Univ. http://yanke23.com, [email protected]
nCv = 5;
getErrRateFunc = @test_getErrRate; % user-defined function for computing the score
% of each chromosome
defParam
cvObj = cvpartition(target,'k',nCv);
userdata.cvObj = cvObj;
userdata.ft = ft;
userdata.target = target;
nFt = size(ft,2);
errs = zeros(1,nFt);
for p = 1:nFt
x = false(1,nFt);
x(p) = true;
errs(p) = getErrRateFunc(x,userdata);
end
[ftScore,ftRank] = sort(errs,'ascend');
end