Skip to main content
1 of 2
Green Falcon
  • 14.2k
  • 10
  • 58
  • 98

Consider that you are doing vector operation, change your cost function to the following:

(1 / m) * sum(((-y) .* (log(h)) - ((1 - y) .* log((1-h)))));

and your gradient to the following:

grad = (1./m) * (x' * (h - y))

Although the latter is just for precedence reassuring.

Green Falcon
  • 14.2k
  • 10
  • 58
  • 98