GithubHelp home page GithubHelp logo

Comments (2)

kszucs avatar kszucs commented on May 27, 2024

Decision function method is not yet implemented. BTW it's pretty straightforward:

class LinearClassifierMixin(ClassifierMixin):
    """Mixin for linear classifiers.

    Handles prediction for sparse and dense X.
    """

    def decision_function(self, X):
        """Predict confidence scores for samples.

        The confidence score for a sample is the signed distance of that
        sample to the hyperplane.

        Parameters
        ----------
        X : {array-like, sparse matrix}, shape = (n_samples, n_features)
            Samples.

        Returns
        -------
        array, shape=(n_samples,) if n_classes == 2 else (n_samples, n_classes)
            Confidence scores per (sample, class) combination. In the binary
            case, confidence score for self.classes_[1] where >0 means this
            class would be predicted.
        """
        if not hasattr(self, 'coef_') or self.coef_ is None:
            raise NotFittedError("This %(name)s instance is not fitted"
                                 "yet" % {'name': type(self).__name__})

        X = check_array(X, accept_sparse='csr')

        n_features = self.coef_.shape[1]
        if X.shape[1] != n_features:
            raise ValueError("X has %d features per sample; expecting %d"
                             % (X.shape[1], n_features))

        scores = safe_sparse_dot(X, self.coef_.T,
                                 dense_output=True) + self.intercept_
        return scores.ravel() if scores.shape[1] == 1 else scores

We need to create a spark version of LinearClassifierMixin, simply map the sklearn's decision_function method on the RDD, something like this:

class SparkLinearClassifierMixin(LinearClassifierMixin, SparkBroadcasterMixin):
    """Mixin for linear classifiers.

    Handles prediction for sparse and dense X.
    """

    __transient__ = ['coef_', 'intercept_']  #broadcastable variables, possibly larger arrays

    def decision_function(self, X):
        check_rdd(X, (sp.spmatrix, np.ndarray))

        mapper = self.broadcast(
            super(LinearClassifierMixin, self).decision_function, X.context)
        return X.map(mapper)

Finally extend SparkLinearSVC to support the functionality above:

class SparkLinearSVC(LinearSVC, SparkLinearClassifierMixin, SparkLinearModelMixin):

We plan to implement it in the next few weeks, but as always, contribution is appreciated :)

from sparkit-learn.

kszucs avatar kszucs commented on May 27, 2024

@mrshanth I saw You've implemented the decision function support. Would You make a pull request please? :)

from sparkit-learn.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.