问题
I am using libsvm for document classification. I use svm.cc and svm.h in my project. I then call svm_train. I save the model in a file using svm_save_model.
I have there categories. The svm model file is:
svm_type c_svc
kernel_type rbf
gamma 0.001002
nr_class 3
total_sv 9
rho -0.000766337 0.00314423 0.00387654
label 0 1 2
nr_sv 3 3 3
SV
1 1 1:0.001 2:0.001 3:0.012521912 5:0.001 15:0.012521912 17:0.012521912 23:0.001
1 1 1:0.001 2:0.014176543 4:0.093235799 6:0.001 7:0.0058630699 9:0.040529628 10:0.001
1 1 11:0.38863495 33:0.08295242 46:0.041749886 58:0.08295242 89:0.08295242 127:0.15338862 -1 1 5:0.001 8:0.0565 10:0.001 13:0.001 18:0.0565 21:0.021483399 34:0.12453384 36:0.001
-1 1 13:0.034959612 34:0.090130132 36:0.034959612 45:0.034959612 47:0.12019824
-1 1 5:0.001 8:0.048037273 13:0.001 18:0.048037273 29:0.14715472 30:0.018360058 36:0.001
-1 -1 9:0.0049328688 12:0.090902344 18:0.1156038 27:0.0049328688 31:0.015144206
What are 1 and -1 before the vector values in the form of index:value ?
回答1:
From the libsvm FAQ:
Q: Can you explain more about the model file?
In the model file, after parameters and other informations such as labels , each line represents a support vector. Support vectors are listed in the order of "labels" shown earlier. (i.e., those from the first class in the "labels" list are grouped first, and so on.) If k is the total number of classes, in front of a support vector in class j, there are k-1 coefficients y*alpha where alpha are dual solution of the following two class problems: 1 vs j, 2 vs j, ..., j-1 vs j, j vs j+1, j vs j+2, ..., j vs k and y=1 in first j-1 coefficients, y=-1 in the remaining k-j coefficients. For example, if there are 4 classes, the file looks like:
+-+-+-+--------------------+
|1|1|1| |
|v|v|v| SVs from class 1 |
|2|3|4| |
+-+-+-+--------------------+
|1|2|2| |
|v|v|v| SVs from class 2 |
|2|3|4| |
+-+-+-+--------------------+
|1|2|3| |
|v|v|v| SVs from class 3 |
|3|3|4| |
+-+-+-+--------------------+
|1|2|3| |
|v|v|v| SVs from class 4 |
|4|4|4| |
+-+-+-+--------------------+
http://www.csie.ntu.edu.tw/~cjlin/libsvm/faq.html#f402
来源:https://stackoverflow.com/questions/18223756/libsvm-model-file-format-no-model-number