Skip to content

MRG: merge sparse and dense SVMs - #576

Merged
larsmans merged 4 commits into
scikit-learn:masterfrom
larsmans:merge-svms
Jan 27, 2012
Merged

larsmans merged 4 commits into
scikit-learn:masterfrom
larsmans:merge-svms

Conversation

@larsmans

Copy link
Copy Markdown
Member

This branch merges support for sparse matrices into the vanilla SVM classes.

I propose a new convention for the SVMs: they support sparse data in predict iff they have been fit on sparse data. This is different from the current behavior of svm.sparse.*, which is to convert dense sample arrays to CSR matrices.

@ogrisel

ogrisel commented Jan 20, 2012

Copy link
Copy Markdown
Member

Thanks heaps \o/.

+1 for the new convention too

@mblondel

Copy link
Copy Markdown
Member

One thing I don't like in the current sparse.SVC implementation is that the dual coefficients are stored in a a sparse matrix. Not only this introduces an API difference between the dense and sparse implementations, there is also no reason to do that: the sparsity of the coefficients has nothing to do with the sparsity of X. I would much prefer if we used the same attributes as for the current dense implementation. This should also make the new merged class smaller and easier to understand.

@larsmans

Copy link
Copy Markdown
Member Author

I was wondering why that was done. If you say sparse coefficients doesn't speed things up (I remember, I believe, @pprett's timings of sparse coefficients in SGD) then I'll be happy to remove them.

@mblondel

Copy link
Copy Markdown
Member

I believe a vector of size n_SV is the most efficient way to store the coefficients (for a binary problem).

@larsmans

Copy link
Copy Markdown
Member Author

I'll look into this over the weekend. Good opportunity to brush up on my knowledge of SVMs :)

@amueller

Copy link
Copy Markdown
Member

Thanks a lot for doing this :)

Could we maybe merge my svm fix before that?

I faced the sparsity issue there, too, and decided to make coef_ sparse for consistency even though that makes little sense.
If you change it for dual_coef_ it wouls make sense to also change it for coef_.

@larsmans

Copy link
Copy Markdown
Member Author

Is that #546? I'd prefer not to have a sparse datastructure anywhere just for consistency; they should only be used when necessary for memory use and/or speed. Won't your patch slow SVMs' predict down?

@amueller

Copy link
Copy Markdown
Member

Yes, it is #546.
My patch doesn't slow predict down. predict doesn't use coef_.
Actually coef_ was not used anywhere previously since it's content didn't make any sense afaik.
I can fix this in my branch but I thought it would be easier to do this later, as you will probably have to touch many places any way.

@mblondel

Copy link
Copy Markdown
Member

@amueller's changes look more localized to me. I wonder if it isn't better to merge this PR first (don't hate me @amueller ;). It you copy / paste the code by hand (not with git merge), it should be fairly easy.

@larsmans

Copy link
Copy Markdown
Member Author

Okay, got the tests. Dense coefficients will take more time, though.

@mblondel

Copy link
Copy Markdown
Member

@larsmans : Do you think it should be addressed in this PR or in another one?

@larsmans

Copy link
Copy Markdown
Member Author

Let's do it in a separate PR. This one's up for review and merge.

@ogrisel

ogrisel commented Jan 23, 2012

Copy link
Copy Markdown
Member

The TODO list in the PR summary tells that the tests and documentation need to be updated. Is it still the case? I think the tests are ok but not sure about the doc.

@larsmans

Copy link
Copy Markdown
Member Author

Updated the docs!

@mblondel

Copy link
Copy Markdown
Member

What's the state of this PR? I may have to touch the bindings at some point...

@larsmans

Copy link
Copy Markdown
Member Author

I believe it's finished, it just needs to merge with master once more. You can merge it manually if you want, I'm a bit busy.

* enable sparse matrix support in formerly dense versions
* remove DenseBaseLibSVM
* move sparse.libsvm to libsvm_sparse
* keep sparse.* behavior: will transform dense data into sparse data
  when fitting (we might want to deprecate this along with the classes)
* document sparsity support in classes.py
@larsmans

Copy link
Copy Markdown
Member Author

Apparently, I screwed up when pushing the doc updates. I redid them, rebased on current master because the PR was no longer automergeable and force-pushed. Reviews, anyone?

@ogrisel

ogrisel commented Jan 27, 2012

Copy link
Copy Markdown
Member

If the full test suite (including doctests) pass on your box, +1 for merging.

@amueller

Copy link
Copy Markdown
Member

+0 for merging, have no time for a review at the moment, methinks.

@larsmans

Copy link
Copy Markdown
Member Author

Yep, all 50 tests + all 9 doctests succeed.

@mblondel

Copy link
Copy Markdown
Member

+1 for merge! Thanks again @larsmans!

larsmans added a commit that referenced this pull request Jan 27, 2012
merge sparse and dense SVM classes
@larsmans
larsmans merged commit 8d066b9 into scikit-learn:master Jan 27, 2012
@ogrisel

ogrisel commented Jan 27, 2012

Copy link
Copy Markdown
Member

Thanks for this "tour de force" indeed.

BTW: on my bot I have for the full suite (code and doc tests):

Ran 786 tests in 62.697s
Ran 15 tests in 10.109s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants