How to use a bag of features object to train a Random fores classifier?

조회 수: 1 (최근 30일)
Hello, I'm using categoryClassifier = trainImageCategoryClassifier(trainingSet, bag) to train ans SVM model. bag is a bag of visual words. How can I derive a TreeBagger model instead of SVM?

채택된 답변

Uttiya Ghosh
Uttiya Ghosh 2020년 7월 14일
편집: Uttiya Ghosh 2020년 7월 15일
Hi Shai,
From my understanding, you want to know how to convert a bag of features into a table of features so that it can be used to train a TreeBagger model. PFB the code that will help you in the conversion process. Here I have used a datatore of 12 images. I have randomly selected 75% of the images for training and remaining for testing my model. I have used 5 trees in my tree bagger model.
setDir = fullfile(toolboxdir('vision'),'visiondata','imageSets');
imds = imageDatastore(setDir,'IncludeSubfolders',true,'LabelSource',...
'foldernames');
[imdsTrain,imdsTest] = splitEachLabel(imds,0.75,'randomize');
bagTrain = bagOfFeatures(imdsTrain);
bagTest = bagOfFeatures(imdsTest);
featureVectorTrain = encode(bagTrain, imdsTrain);
featureVectorTest = encode(bagTest, imdsTest);
B = TreeBagger(5,featureVectorTrain,imdsTrain.Labels);
imdsPred = predict(B,featureVectorTest);
acc = (nnz(imdsPred == imdsTest.Labels))/length(imdsTest.Labels);
For more information, refer to the following links.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by