From a77bb6f4ef335d7892d292333a84e24e28bea048 Mon Sep 17 00:00:00 2001 From: Naftali Harris Date: Wed, 11 Jun 2014 15:48:32 -0700 Subject: [PATCH] Check if margin > 0, not if prob > 0.5 This avoids an unnecessary computation and also possible math overflow errors. --- python/pyspark/mllib/classification.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/python/pyspark/mllib/classification.py b/python/pyspark/mllib/classification.py index 1c0c536c4fb3d..822f71edc2f56 100644 --- a/python/pyspark/mllib/classification.py +++ b/python/pyspark/mllib/classification.py @@ -63,8 +63,7 @@ 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)) - return 1 if prob > 0.5 else 0 + return 1 if margin > 0 else 0 class LogisticRegressionWithSGD(object):