How to find the score of a SVM classifier in MATLA

2019-08-11 08:58发布

I am currently doing a project on multimodal biometrics (fusion at score level). So I need to get the score before fusion. Can anyone tell me how to get the score of the particular test sample using a trained SVM classifier?

I have used the inbuilt svmtrain and svmclassify functions in MATLAB.

1条回答
相关推荐>>
2楼-- · 2019-08-11 09:37

Unfortunately the svmclassify function only outputs the label of the class and no distance (score). You will have to write your own classification function. Luckily, this is very easy: As you do have the Statistics Toolbox with svmclassify, you can easily look at the source code of the function with

edit svmclassify

You will see that most of the function is checking inputs etc. The important parts are scaling the data:

sample(:,c) = svmStruct.ScaleData.scaleFactor(c) * ...
              (sample(:,c) +  svmStruct.ScaleData.shift(c));

and doing the classification using a built-in function svmdecision:

outclass = svmdecision(sample,svmStruct);

From the definition of svmdecision you will see that it outputs the distance f, but svmclassify ignores it. You could therefore easily create a new function, which looks almost exactly like svmclassify, but also returns f:

1   function [outclass,f] = svmclassify(svmStruct,sample, varargin)
...
112    [outclass,f] = svmdecision(sample,svmStruct);
...
158    outclass = []; f = [];

You will find that svmdecision is a private function. To be able to call it from your function, you have to make a copy in your local folder (or any subfolder).

查看更多
登录 后发表回答