Commits

Lan Zagar  committed d88871b

Nicer and faster cost computation.

  • Participants
  • Parent commits dd755d9

Comments (0)

Files changed (1)

File mlclass/logistic_regression.py

         m = X.shape[0]
         sx = sigmoid(X.dot(theta))
 
-        j = -y.dot(np.log(sx)) - (1 - y).dot(np.log(1 - sx))
+        j = -np.log(np.where(y, sx, 1 - sx)).sum()
         j += self.lambda_ * theta.dot(theta) / 2.0
         j /= m