Score calculation in ClassificationSVM using linear kernel function
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Gaussian Process Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!