liblinear icon indicating copy to clipboard operation
liblinear copied to clipboard

Is there a way to read out support vectors?

Open AtlantixJJ opened this issue 5 years ago • 1 comments

Hi, just want to know how can I read the support vectors out (in python interface)? Thanks.

AtlantixJJ avatar Apr 29 '20 01:04 AtlantixJJ

See the following faq:

Q: How could I know which training instances are support vectors?

Some LIBLINEAR solvers consider the primal problem, so support vectors are not obtained during the training procedure. For dual solvers, we output only the primal weight vector w, so support vectors are not stored in the model. This is different from LIBSVM.

To know support vectors, you can modify the following loop in solve_l2r_l1l2_svc() of linear.cpp to print out indices:

     for(i=0; i<l; i++)
     {
             v += alpha[i]*(alpha[i]*diag[GETI(i)] - 2);
             if(alpha[i] > 0)
                     ++nSV;
     }

Note that we group data in the same class together before calling this subroutine. Thus the order of your training instances has been changed. You can sort your data (e.g., positive instances before negative ones) before using liblinear. Then indices will be the same.

On 2020-04-29 09:09, Jianjing Xu wrote:

Hi, just want to know how can I read the support vectors out (in python interface)? Thanks.

-- You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub [1], or unsubscribe [2]. [ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/cjlin1/liblinear/issues/61", "url": "https://github.com/cjlin1/liblinear/issues/61", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } } ]

Links:

[1] https://github.com/cjlin1/liblinear/issues/61 [2] https://github.com/notifications/unsubscribe-auth/ABI3BHWFGKLWHYKCYAPMFRDRO544JANCNFSM4MTJYAXA

cjlin1 avatar Apr 29 '20 01:04 cjlin1