1. Matlab using TreeBagger (it is actually like Random Forest)
==========================================
load ionosphere;
noBag = 5;
myBag = TreeBagger( noBag , X, Y, 'OOBPred','on' , 'oobvarimp' ,'on' );
// increase in prediction error if the values of that variable are permuted across OOB observations.
// The more increase in prediction Error ==> The more important the variable is
oobVarImp = myBag.OOBPermutedVarDeltaError
// re-substitution error
varImp = zeros( noBag, noFeature)
for i=1:noBag
varimportance( myBag.Trees{i})
end
========== COMPLETE CODE==========
function fromRF
load ionosphere;
noBag = 5;
myBag = TreeBagger( noBag , X, Y, 'OOBPred','on');
varRanking = zeros( noBag , size(X,2) ) ;
for i=1:noBag
[ val ,varRanking( i , :) ]= sort( varimportance( myBag.Trees{i}) ,'descend')
end
// suppose finally taking top ranked 5 from all folds
topRank=5;
selectedFeat=[]
for i=1:noBag
selectedFeat = union( selectedFeat , varRanking( i , 1:topRank) );
end
display('done');
end
Comments
Post a Comment