How to use a bag of features object to train a Random fores classifier?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Shai Kendler
le 1 Juin 2020
Modifié(e) : Uttiya Ghosh
le 15 Juil 2020
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?
0 commentaires
Réponse acceptée
Uttiya Ghosh
le 14 Juil 2020
Modifié(e) : Uttiya Ghosh
le 15 Juil 2020
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Get Started with Statistics and Machine Learning Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!