Score calculation in ClassificationSVM using linear kernel function

15 views (last 30 days)
I have binary ClassificationSVM classifier: svmModel. It's trained using linear kernel. I know the score of test data can be obtained through predict(svmModel, testdata). I want to imitate the actual score calculation in the function predict, so I followed the documentation of ClassificationSVM which says:
The linear SVM score function is f(x)=(x/s)′β+b where: x is an observation (corresponding to a row of X). s is the kernel scale and β is the vector of fitted linear coefficients. b is the bias term (corresponding to SVMModel.Bias).
However, when I calculate the score using f(x)=(x/s)′β+b, the score is different from what is returned by the function predict.
My svmModel:
Beta is [-0.9608 0.4401 -1.8665 -0.0358 -1.2389 0.9508 -1.9353 -2.9381 2.2893 1.4051 1.4547] svmModel.KernelParameters.Scale is 1.8839
My test data (1 observation) is [8.939 8.497 7.899 6.755 5.674 7.433 8.600 10.355 5.017 7.442 9.668]. Score from the function predict is 3.2217 -3.2217. Score from f(x)=(x/s)′β+b is -10.9064.
Is there any other steps required besides f(x)=(x/s)′β+b or I am using some parameters wrong ?
Thanks.

Accepted Answer

Ilya
Ilya on 21 Jul 2015
In 14a and 14b, the Beta coefficients of an SVM model need to be divided by KernelParameters.Scale to get correct predictions. In 15a, dividing by the scale is no longer necessary.
  3 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!