필터 지우기
필터 지우기

Score calculation in ClassificationSVM using linear kernel function

조회 수: 4 (최근 30일)
Yancey Li
Yancey Li 2015년 7월 20일
댓글: liang shuaibing 2020년 7월 23일
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.

채택된 답변

Ilya
Ilya 2015년 7월 21일
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
liang shuaibing
liang shuaibing 2020년 7월 23일
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 2020년 7월 23일
ok ,get same score ,need to normalize it at first

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environmental Science에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by