Is there a reason why OneVsRestClassifier does not implement decision_function?
It looks like the correct implementation is just to concatenate
together the decision_function outputs of the individual estimators_.

The current setup is kind of frustrating to use since the interfaces
of LinearSVC and SVC are so different. I've set up my own wrapper
around SVC. (As the comment says, this wrapper is the only way to do
one-vs-rest SVM classification without duplicating the training
data) I'm not sure why there isn't something like this in sklearn already.


from sklearn.multiclass import OneVsRestClassifier
from sklearn.svm import SVC
import numpy as np

class DenseMulticlassSVM(OneVsRestClassifier):
    """
    sklearn does very different things behind the scenes depending
    upon the exact identity of the class you use. The only way to
    get an SVM implementation that works with dense data is to use
    the `SVC` class, which implements one-against-one
    classification. This wrapper uses it to implement one-against-
    rest classification, which generally works better in my
    experiments.

    To avoid duplicating the training data, use only numpy ndarrays
    whose tags.c_contigous flag is true, and which are in float64
    format.
    """

    def __init__(self, C, kernel='rbf', gamma = 1.0, coef0 = 1.0, degree = 3):
        estimator = SVC(C=C, kernel=kernel, gamma = gamma, coef0 =
1.0, degree = 3)
        super(DenseMulticlassSVM,self).__init__(estimator)

    def decision_function(self, X):

        return np.concatenate( [ estimator.decision_function(X) for
estimator in self.estimators_ ], axis = 1)

------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second 
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
_______________________________________________
Scikit-learn-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general

Reply via email to