Difference between individual and cumulative oobMargin of TreeBagger

Why aren't the following two plots the same?
b = TreeBagger(500,X,Y,'oobpred','on');
mc = oobMargin(b,'mode','cumulative');
mi = oobMargin(b,'mode','individual');
figure; plot(mc.')
figure; plot(bsxfun(@rdivide,cumsum(mi.'),(1:500).'))

 채택된 답변

Ilya
Ilya 2011년 6월 17일

0 개 추천

When you ask for an OOB margin from one tree, you get zero if this observation was in bag for this tree. The margin is undefined in this case, and TreeBagger returns 0 by default. The cumulative calculation averages over trees for which this observation was out of bag only. Check this out:
>> load fisheriris
>> b = TreeBagger(10,meas,species,'oobpred','on');
>> mi = oobMargin(b,'mode','individual');
>> mi(1,:)
ans = 1 0 0 0 1 0 1 1 0 0
>> b.OOBIndices(1,:)
ans = 1 0 0 0 1 0 1 1 0 0
>> mc = oobMargin(b,'mode','cumulative');
>> mc(1,:)
ans = 1 1 1 1 1 1 1 1 1 1

댓글 수: 1

Thank you Ilya. Not including the in-bag samples is the key.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

K
K 2011년 6월 21일
Code using the individual mode that produces the same plot as the cumulative mode is the following.
load ionosphere
b = TreeBagger(500,X,Y,'oobpred','on');
mc = oobMargin(b,'mode','cumulative');
mi = oobMargin(b,'mode','individual');
figure; plot(mc.')
% figure; plot(bsxfun(@rdivide,cumsum(mi.'),(1:500).'))
cumavg = zeros(size(mc));
cumavg(:,1) = mi(:,1);
for ii = 1:size(mc,1)
for jj = 2:size(mc,2)
if sum(b.OOBIndices(ii,1:jj)) == 0
cumavg(ii,jj) = mi(ii,1);
else
micurrent = mi(ii,1:jj);
cumavg(ii,jj) = mean(micurrent(b.OOBIndices(ii,1:jj)));
end
end
end
figure; plot(cumavg.')

카테고리

태그

질문:

K
K
2011년 6월 16일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by