Reputation: 167
I'm trying to calculate the loss function in Logistic Regression but end up getting a math error in it. can you please help me rectify this error?
def loss(y,a):
L = (-y*math.log(a)-(1-y)*math.log(1-a)).mean()
return L
Upvotes: 0
Views: 280
Reputation: 4264
You are getting the error because you are trying to find the log of a negative number (i.e. a
is becoming negative). From your equation, I infer y
is the true value and a
is the predicted value. And the predictions come for the eqution below:
So there is no way a
can be negative, so kindly check your prediction function definition.
Upvotes: 1