Score calculation in ClassificationSVM using linear kernel function

6 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Ilya
Ilya el 21 de Jul. de 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 comentarios
liang shuaibing
liang shuaibing el 23 de Jul. de 2020
hi ,I also have this problem ,but the Scale in my model is 1 . so I still can not get the same predictions. I use the example at matlab website .here is my matlab code and result .can you teach me your calculate way?thanks
load fisheriris
inds = ~strcmp(species,'setosa');
X = meas(inds,3:4);
y = species(inds);
SVMModel = fitcsvm(X,y)
[~,score] = predict(SVMModel,X);
score(1:3,:)
# run result!!!!!!!!!!!!!!!!!!!!
ans =
1.0000 -1.0000
1.2112 -1.2112
0.3380 -0.3380
calculate_by_me=transpose(X/SVMModel.KernelParameters.Scale).*SVMModel.Beta+SVMModel.Bias;
calculate_by_me(:,1:3)
# run result!!!!!!!!!!!!!!!!!!!!
ans =
-4.1551 -4.5917 -3.7185
-11.2598 -11.0344 -11.0344
liang shuaibing
liang shuaibing el 23 de Jul. de 2020
ok ,get same score ,need to normalize it at first

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Environmental Science en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by