forked from viggin/yan-prtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ftSel_boost.m
37 lines (31 loc) · 1.07 KB
/
ftSel_boost.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 [ftSubset,ftScore] = ftSel_boost(ft,target,param)
%Feature selection using AdaBoost with the stump weak learner
%
% FT : sample matrix, each row is a sample.
% TARGET : a column vector, class labels for X starting from 1. Only supports
% binary class problems.
% 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:
% FTSUBSET: ordered selected features (most important first)
% FTSCORE: not returned.
%
% Ke YAN, 2016, Tsinghua Univ. http://yanke23.com, [email protected]
[nSmp,nFt] = size(ft);
nSel = min(10,nFt); % number of features to select
defParam
if any(target ~= 1 & target ~= 2)
error('Only supports binary class problems.')
end
Y = (target-1.5)*2;
model = adaboost(@stump,nSel);
model.train(ft,Y);
nSel = min(nSel,model.realLen);
ftSubset = nan(1,nSel);
for p = 1:nSel
ftSubset(p) = model.weakLearners{p}.dim;
end
ftScore = model.alpha;
end