필터 지우기
필터 지우기

How to find the classification accuracy of Random Forest?

조회 수: 12 (최근 30일)
MA-Winlab
MA-Winlab 2019년 5월 5일
답변: Zenin Easa Panthakkalakath 2019년 5월 14일
I am trying to use Random Forest with 10 fold cross validation. My code is shown below:
I would to find the correct rate of the classifier, but seems that classpref does not work with TreeBagger. In this case how can find the accuracy of the classifier given that I use cross validation ?
cvFolds = crossvalind('Kfold', FeatureLabSHUFFLE, k); %# get indices of 10-fold CV
cp = classperf(FeatureLabSHUFFLE);
for i = 1:k %# for each fold
testIdx = (cvFolds == i); %# get indices of test instances
trainIdx = ~testIdx; %# get indices training instances
%Random Forest
RFModel = TreeBagger(10,FeatureMTX(trainIdx,:), FeatureLabSHUFFLE(trainIdx));
pred = predict(RFModel, FeatureMTX(testIdx,:));
%# evaluate and update performance object
cp = classperf(cp, pred, testIdx);
end
cp.CorrectRate;

답변 (1개)

Zenin Easa Panthakkalakath
Zenin Easa Panthakkalakath 2019년 5월 14일
Hi MA-Winlab,
Have a look at the following documentation that talks about Bootstrap Aggregation (Bagging) of Classification Trees Using TreeBagger. The example shows how to find the Classification accuract and loss.
Regards,
Zenin

Community Treasure Hunt

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

Start Hunting!

Translated by