Even though it's late, this answer might help someone else.
In the part of your code.
... + (1-yval)* np.log(1-sigmoid(np.dot(w.transpose(), xi.transpose())))
may be the np.dot(w.transpose(), xi.transpose())
function is spitting larger values(above 40 or so), resulting in the output of sigmoid( )
to be 1
. And then you're basically taking np.log
of 1-1
that is 0
. And as DevShark has mentioned above, it causes the RuntimeWarning: Divide by zero...
error.
How I came up with the number 40 you might ask, well, it's just that for values above 40 or so sigmoid function in python(numpy) returns 1.
.
Looking at your implementation, it seems you're dealing with the Logistic Regression algorithm, in which case(I'm under the impression that) feature scaling is very important.
Since I'm writing answer for the first time, It is possible I may have violated some rules/regulations, if that is the case I'd like to apologise.