Github user jkbradley commented on a diff in the pull request:

    https://github.com/apache/spark/pull/5137#discussion_r27335277
  
    --- Diff: python/pyspark/mllib/classification.py ---
    @@ -126,20 +172,33 @@ def predict(self, x):
                 return x.map(lambda v: self.predict(v))
     
             x = _convert_to_vector(x)
    -        margin = self.weights.dot(x) + self._intercept
    -        if margin > 0:
    -            prob = 1 / (1 + exp(-margin))
    +        if self.numClasses == 2:
    +            margin = self.weights.dot(x) + self._intercept
    +            if margin > 0:
    +                prob = 1 / (1 + exp(-margin))
    +            else:
    +                exp_margin = exp(margin)
    +                prob = exp_margin / (1 + exp_margin)
    +            if self._threshold is None:
    +                return prob
    +            else:
    +                return 1 if prob > self._threshold else 0
             else:
    -            exp_margin = exp(margin)
    -            prob = exp_margin / (1 + exp_margin)
    -        if self._threshold is None:
    -            return prob
    -        else:
    -            return 1 if prob > self._threshold else 0
    +            best_class = 0
    +            max_margin = 0.0
    +            for i in range(0, self.numClasses - 1):
    +                if x.size + 1 == self.dataWithBiasSize:
    --- End diff --
    
    This test can be moved outside of the loop.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to