Repository navigation
MRG Svm coef sign in liblinear and libsvm, fixing libsvm coef_ - #546
Conversation
|
Thanks Andreas, you are doing an amazing job moving forward these issues. |
|
thanks :) comments? |
|
I think you did the right thing but I'd like to test it and think a bit more about the implications before merging. |
|
Sure. The tests should all run fine. I'll add the libsvm stuff to the pull request tonight. Then you can test them together. |
There was a problem hiding this comment.
Does not look pep8 to me :)
What about:
sv1 = self.support_vectors_[
sv_locs[class1]:sv_locs[class1 + 1], :]Or better this code should be factorized in a private python function that would both reduce the complexity of the method and increase its readability and respect pep8 by removing 2 indent levels.
There was a problem hiding this comment.
Whoops... I'm sorry. Factorization seems like a good idea.
|
@mblondel : I added an example but I am not very happy with how it looks. If there is no obvious way to actually use the old |
|
Please add a (very small) description of the changes on the first lines of linear.cpp, something like: that really helps when applying upstream changes |
|
Will do! |
|
Maybe you could even put a link to this pull request #546. |
|
REBASE :) |
Conflicts: sklearn/svm/base.py sklearn/svm/liblinear.c sklearn/svm/sparse/base.py
|
Merged master. |
|
I'd like to see some timings for both, e.g. from the document classification example (maybe with |
|
As I said before, [edit] Forgot what I said. Writing a python |
|
Sorry, my bad, should have remembered that. We might want to let this depend on |
|
I'm not sure what the L1 penalty means (can you give a reference?) and whether it will result in sparse primal solutions. Don't you think it is ok to let the user worry whether they want to convert the matrix to a dense representation or not? |
|
As far as I can see, there is no l1 penalization implemented in LibSVM, btw. While this might not be clear from the title of the pr cough, the change to "coef_" only applies to LibSVM, not LibLinear, |
|
The Liblinear paper describes L1-regularized SVMs. When you run the document classification example, you'll get output like and where the last figure indicates the fraction of non-zero elements in |
|
As I said in my edit above, what I did only changed things in libsvm. |
|
Ok. I thought you were working on Liblinear, I hadn't actually looked at the changes yet. |
|
Sorry for mixing something unrelated in the pull-request... |
There is no gain to expect by storing the dual coefficients in a scipy @amueller: I think you should focus on merging your PR in its current |
|
@mblondel ok :) Any suggestions? I think it should be ready for merge. |
|
+1 for merging. |
+1 |
MRG Svm coef sign in liblinear and libsvm, fixing libsvm coef_
The issue was that the signs of the decision function are flipped for the two class case in liblinear and libsvm.
To put it otherwise, some wrapping code sorts classes in ascending order while the libsvm code expects the first class in a two class setting to be '+1' and the second one '-1'.
I "fixed" this by swapping the roles of +1 and -1 in liblinear.
I felt this is the cleanest solution. I am a bit weary of touching the liblinear code since that could complicate upgrades.
What do you think?
The main reason that I did not do this in cython is the following:
The Cython wrappers get their coefs for prediction from the Python class.
If I want to switch the sign there, I'll have to switch it back when doing predictions.
So I have to switch it after fit, before calling predict or decision function and then switch again on the value of the decision function.
This seemed ugly and confusing to me.
There is also a second thing this pr fixes (yeah I know, shouldn't do that):
the primal "coef_" of libSVM are now calculated correctly in the one-vs-one case.