Reputation: 123
I am new to libsvm. I am having trouble understanding the output of libsvm. I just want to know how do you find the alpha_i of all the support vectors? Does the parameter model.sv_coef
give you the alpha_i
or alpha_i*y_i
? and the other main question that I wanted to ask is what does model.SVs
give? I am using libsvm in matlab and the output I am getting when I look for model.SVs
is:
my training set is:
-1 1:0.747253 2:0.894737
+1 1:0.692308 2:-0.824561
-1 1:0.362637 2:0.789474
+1 1:0.769231 2:-0.321637
my test set:
-1 1:-0.351648 2:-0.602339
+1 1:-0.21978 2:-0.263158
var1=model.sv_indices
>>var1 =
2
4
3
model.SVs
>>ans =
(1,1) 2.0000
(2,1) 4.0000
(3,1) 3.0000
(1,2) -0.2204
(2,2) 0.2870
(3,2) 0.9774
(1,3) 1.1592
(2,3) 0.7978
(3,3) -0.3999
(1,4) -0.3999
(2,4) 0.0250
(3,4) 0.7548
(1,5) 0.7978
(2,5) 0.6952
(3,5) 0.0250
what are these (1,1),(2,1),(3,1)...? I mean I have only 4 training set so how can this second index go to 5 and only two test set so how can the first index go to 3.
Upvotes: 2
Views: 979
Reputation: 12699
model.sv_coef
contains all the alpha_i * y_i
, model.SVs
are all the support vectors x_i
. The weights can be written as
w = model.SVs' * model.sv_coef;
b = -model.rho;
You may not need to care much about the labeling of (1,2), (1,3)...m.nSV
will give you the number of support vectors for each class. Since you have only two classes, the answer should be a 2*1
vector with each row representing the support vector number for the corresponding class. Check this document for more details.
Upvotes: 2