def predict(self, data, prob=False):
"""Computes the logistic probability of being a positive example
Parameters
----------
data : ndarray (n-rows,n-features)
Test data to score using the current weights
prob : Boolean
If set to true, probability will be returned, else binary classification
Returns
-------
0 or 1: int
0 if probablity is less than 0.5, else 1
"""
data = np.column_stack((np.ones(data.shape[0]), data))
hypothesis = LogisticRegression.sigmoid(np.dot(data, self.theta))
if not prob:
return np.where(hypothesis >= .5, 1, 0)
return hypothesis
评论列表
文章目录