1

After I get the svm_model from svm_train using libsvm, how do I get the rho and SVs from the model? I know that these values are printed out when I get the model, but I have no idea how to get the SVs. ex:

svm_model = svmutil.svm_train(Labels,X, svm_options)

Now, how to get the rho values and SVs from svm_model ?

rchhe
  • 141
  • 2
  • 7
  • I thought svm_model had accessors for rho and SVs.... What does the object above have in it? – dfb Mar 02 '11 at 00:57

3 Answers3

4

If you are using the svmutil package, then you can get support vectors, coefficients and rho as follows,

m = svmutil.svm_train( y, xs, "-s 3 -t 2" ) # EPSILON_SVR and RBF kernel
rho = m.rho[0] 
svs = m.get_SV() # Dictionary with indices 1, 2 corresponding to i-th dim on support vector
sv_coeffs = m.get_sv_coef()
Arun Chaganty
  • 341
  • 3
  • 13
1

After almost a month, I found that there is no way to get the rho or SVs from the svm_model so generated. If somebody came looking to find one, use scikit-learn which gives you the support vectors, the dual intercepts, and rho value without any hassle. Additionally, it is faster than python implementation of libsvm and support numpy arrays and matrices.

rchhe
  • 141
  • 2
  • 7
1

If you run the executable svm_train.exe which comes with libSVM installation itself, you can find that it generates a model file as output, XXX.model. If you inspect this model with an editor, you can find there the rho values and the list of the support vectors.

Looks like in the C++/C code, there is not support to extract this information from the object.

Nikana Reklawyks
  • 3,233
  • 3
  • 33
  • 49
sramij
  • 4,775
  • 5
  • 33
  • 55