-
-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX Issue 379 and use the opportunity to refactor libsvm code
Sparse SVC's would try to use the dense decision_function, since SparseBaseLibSVM did not override that method. Solution: factor out non-common code to DenseBaseLibSVM. (@diogojc's test program still crashes, but with an appropriate error message.) Also, leverage superclass __init__ in SparseBaseLibSVM
- Loading branch information
Showing
3 changed files
with
62 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87c8664
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.
Thanks for fixing this! Why does the test program crash? I thought that it should work.
87c8664
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 needs to construct the
sparse.SVC
withprobability=True
. We could make this the default behavior quite easily, but I don't oversee the consequences apart from an extra O(|C|²) memory allocation.87c8664
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.
I think that libsvm fits some kind of logistic regression on top of the SVM when
probability=True
(as described by Platt) so there's an overhead. But I'm curious whyOneVsRestClassifier
doesn't detect thatSVC
has adecision_function
method. Normally, it falls back topredict_proba
only whendecision_function
is not present.87c8664
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.
decision_function
isn't implemented for sparse SVMs, but in the old inheritance tree, it inherited the one fromBaseLibSVM
. So,OneVsRestClassifier
detected the densedecision_function
even for sparse SVMs, which didn't work and raised an exception because of missingself._support
.In the new situation,
decision_function
is inDenseBaseLibSVM
so it's no longer inherited by the sparse SVM classes andpredict_proba
is used instead.87c8664
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 thanks for the clarification. I guess
decision_function
should be implemented for sparse SVMs as well then. Maybe @fabianp as an opinion on this.87c8664
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.
@mblondel: sure, go for it!
87c8664
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.
+1 for a sparse
decision_function
, but may I request that the new inheritance hierarchy be preserved? It's bigger, but also more robust, I hope.