I'm new to matlab as well as LIBSVM. I calculated feature vector for every point stating r,g,b values of point in single vector and stored it in .mat
file. Currently I'm having around 420 points and 4 classes viz Red/Green/Blue/Other. Now I want to pass this .mat file to train libsvm and based on that classify the newly arriving test point, whether it is red or blue or green or other. Need not to mention, its a multiclass classification and I don't even know how to deal with it ? svmtrain(TrainingSet,Groups,'kernel_function','rbf');
where TrainingSet
is my 420*4
feature vector set and Groups
is class name. Thanks in advance for help.
You can try one-vs-all approach with libsvm.
model = cell(4,1);
for k=1:4
model{k} = svmtrain(double(TrainingSet==k), Groups, '-c 1 -g 0.2 -b 1');
end
Then in your test process, just calculate the probability of different labels:
pr = zeros(numTest,4);
for k=1:4
[~,~,p] = svmpredict(double(testLabel==k), TestSet, model{k}, '-b 1');
pr(:,k) = p(:,model{k}.Label==1); %# probability of class==k
end
and your label prediction will be the one with highest probability:
[~,predctedLabel] = max(pr,[],2);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.