提交 b86db517 编写于 作者: X Xiangrui Meng

[SPARK-2552][MLLIB] stabilize logistic function in pyspark

to avoid overflow in `exp(x)` if `x` is large.

Author: Xiangrui Meng <meng@databricks.com>

Closes #1493 from mengxr/py-logistic and squashes the following commits:

259e863 [Xiangrui Meng] stabilize logistic function in pyspark
上级 9564f854
......@@ -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))
return 1 if prob > 0.5 else 0
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册