Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Davies Liu committed Nov 18, 2014
1 parent 2231a5f commit e4acd76
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions python/pyspark/mllib/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@

class LinearBinaryClassificationModel(LinearModel):
"""
Represents a linear binary classification model that predicts to which
of a set of categories an example belongs. The categories are represented
by double values: 0.0, 1.0, 2.0, etc.
Represents a linear binary classification model that predicts to whether an
example is positive (1.0) or negative (0.0).
"""
def __init__(self, weights, intercept):
super(LinearBinaryClassificationModel, self).__init__(weights, intercept)
Expand All @@ -44,9 +43,9 @@ def setThreshold(self, value):
"""
:: Experimental ::
Sets the threshold that separates positive predictions from negative predictions. An example
with prediction score greater than or equal to this threshold is identified as an positive,
and negative otherwise. The default value is 0.5.
Sets the threshold that separates positive predictions from negative
predictions. An example with prediction score greater than or equal
to this threshold is identified as an positive, and negative otherwise.
"""
self._threshold = value

Expand All @@ -60,7 +59,8 @@ def clearThreshold(self):

def predict(self, test):
"""
Predict values for a single data point or an RDD of points using the model trained.
Predict values for a single data point or an RDD of points using
the model trained.
"""
raise NotImplementedError

Expand Down Expand Up @@ -106,15 +106,16 @@ def __init__(self, weights, intercept):

def predict(self, x):
"""
Predict values for a single data point or an RDD of points using the model trained.
Predict values for a single data point or an RDD of points using
the model trained.
"""
if isinstance(x, RDD):
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.0 + exp(-margin))
prob = 1 / (1 + exp(-margin))
else:
exp_margin = exp(margin)
prob = exp_margin / (1 + exp_margin)
Expand Down Expand Up @@ -200,7 +201,8 @@ def __init__(self, weights, intercept):

def predict(self, x):
"""
Predict values for a single data point or an RDD of points using the model trained.
Predict values for a single data point or an RDD of points using
the model trained.
"""
if isinstance(x, RDD):
return x.map(lambda v: self.predict(v))
Expand Down

0 comments on commit e4acd76

Please sign in to comment.