开发者

How to get support vectors and rho values from svm_model (in Python)?

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 ?


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()


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜