ml-glossary
ml-glossary copied to clipboard
The cost function code return opposite sign
#Take the error when label=1 class1_cost = -labels*np.log(predictions)
#Take the error when label=0
class2_cost = (1-labels)*np.log(1-predictions)
#Take the sum of both costs
cost = class1_cost + class2_cost
In this code, it seem like class1 return positive cost and class2 return negative cost, wouldn't they cancel when added?
If the labels can only be 1 or 0, one of the costs will always be 0.
-0 * anything = 0
Or
1-1 * anything = 0
What I mean was, when label is 0, (1-0)log(1-p) will give negative cost, should be (label-1)log(1-p), for positive cost, or I could be missing a point here
@SendToSpace You're correct. The - sign got moved inside the parens in the equation just above the code as well.
Nice catch if you have time for a pr that would be awesome!
Hey @bfortuner, Can I make a PR for this? I'm just a beginner wanted to start contributing ot Open Source.