Classification needs to distinguish uncertainty from confidently choosing the wrong class. A loss should therefore charge a much larger cost when a predicted probability disagrees with the true binary label. The logarithm does that, but only if its input is kept away from zero.
Implement bce_loss(p, y) as a batch mean. Theory gives the two label cases; clip probabilities before either logarithm and return a Python float.
p and binary y have matching (n_samples,) shapes.p to [1e-12, 1 - 1e-12] before logs.float.0.0 and 1.0 inputs must produce a finite loss.Open one at a time. Each gives away a little more than the last.
Each label selects one of two complementary probability terms.
Clip once, then form both log(p) and log(1 - p) before taking the negative mean.
No results yet
Run your code to check it against the examples, or submit to run every test.