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

    https://github.com/apache/spark/pull/1493#discussion_r15541942
  
    --- Diff: python/pyspark/mllib/classification.py ---
    @@ -63,7 +63,10 @@ class LogisticRegressionModel(LinearModel):
         def predict(self, x):
             _linear_predictor_typecheck(x, self._coeff)
             margin = _dot(x, self._coeff) + self._intercept
    -        prob = 1/(1 + exp(-margin))
    +        if margin > 0:
    +            prob = 1 / (1 + exp(-margin))
    +        else:
    +            prob = 1 - 1 / (1 + exp(margin))
    --- End diff --
    
    Better would be
    ```python
    prob = exp(margin)/(1 + exp(margin))
    ```
    because for very small probabilities this computation is essentially doing 
1 - 1.  For example:
    
    ```python
    >>> from math import exp
    >>> margin = -40
    >>> 1 - 1 / (1 + exp(margin))
    0.0
    >>> exp(margin)/(1 + exp(margin))
    4.248354255291589e-18
    >>>
    ```


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to