New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP decision_function for sparse SVC #1586
Conversation
|
||
""" | ||
# multi class: | ||
clf = svm.SVC(kernel='linear', C=0.1).fit(iris.data, iris.target) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the data is not sparse, is it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a csr matrix, even if the data itself isn't exactly sparse. Is there a better dataset to use? Many other tests in the file make use of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok sorry for the noise. I didn't see that the data was converted to sparse at the top of the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test would be more robust if the matrix actually contained some zeroes. You can force some features to zero, for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E.g.
rng = check_random_state(42)
iris.data *= rng.random_integers(0, 1, iris.data.shape)
Looks good from a quick review. I am wondering: would it make sens to have a test checking that the sparse and dense version of the svm solver lead to the same predictions. We need to be really careful to have plenty of tests, or we'll let bugs go through. |
@GaelVaroquaux see #1572 ;) |
Would feel safer if @larsmans could have a look. |
I think this can effectively be combined with #1573 -- if we only implement |
I can't build this:
|
I am still getting an off-by-one error in the test, but fixing now. |
This should build fine now |
prediction, | ||
clf.classes_[(clf.decision_function(X) > 0).astype(np.int).ravel()]) | ||
expected = np.array([[-1.], [-0.66], [-1.], [0.66], [1.], [1.]]) | ||
assert_array_almost_equal(clf.decision_function(X), expected, 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure we want such a test. I think the one against dec
and he other one above are the important ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does make sure we don't screw up in coef_
and decision_function
at the same time :)
Hardcoded values aren't pretty, but since the SVM code is a bit shaky sometimes, it's ok with me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, lets keep it there.
I think this looks good. Let's wait for @larsmans verdict, though. |
@zaxtax could you please rebase again? Sorry for the inconvenience! |
…into svm-sparse-decision-function Conflicts: sklearn/svm/libsvm_sparse.c
Ok rebased |
@larsmans sorry for pestering you again, I think it would be great if you had the time to have a look... |
The code looks good, but it needs a few more tests. A simple loop over the kernels (except linear) to check that |
(A check that |
@@ -71,6 +71,15 @@ def test_svc(): | |||
sp_clf.predict_proba(T2), 4) | |||
|
|||
|
|||
def test_kernels(): | |||
kernels = ["poly", "rbf", "sigmoid", "precomputed"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"precomputed"
doesn't make sense here.
I just did some testing and it turns out the |
Aha:
|
I just tried to chase the bug, but I've no idea where in the jumbled mess of LibSVM and our wrapper code it is. Giving up for now. |
Yea, I've been baffled by this error. I've been visualizing it all week to On Sun, Mar 17, 2013 at 9:52 AM, Lars Buitinck notifications@github.comwrote:
|
Any news on this guy? :) |
I still can't figure it out. Help!!!! On Fri, Apr 19, 2013 at 2:35 AM, Jaques Grobler notifications@github.comwrote:
|
Hi! |
No, it doesn't work, it doesn't pass the tests. Both @zaxtax and I have spent quite some time on this issue but neither of us could figure it out. |
@zaxtax I added a test for the binary case and that even core dumps. It looks to me as if you missed treating the |
It seems that is the way it is done in the other functions, too, though I don't really understand what is happening there.... |
Maybe similarly stupid question / remark: |
Closing this PR in favor of the rebased #4189. |
This resolves issue #73, comes with new passing test.