Binary cross-entropy 2026-10-14
Let follow a Bernoulli distribution with true event probability , and let the model report event probability . The binary cross-entropy is its expected logarithmic loss:
For , it is minimized at , where the value is binary entropy . An individual outcome has loss when and when ; the binary cross-entropy averages those two cases using the true probabilities.
For , truthful reporting gives bits. Reporting gives one bit. Reporting gives
Both and select zero if one predicts only the more likely binary outcome. Their predicted probabilities are very different, however, and cross-entropy reveals the cost of underestimating the event that occurs a quarter of the time. Endpoint losses are computed using the realized outcome rather than multiplying zero by an undefined logarithm.
Figure 1.
The expected logarithmic loss is minimized by reporting the true event probability
. The true Bernoulli distribution has parameter . The blue curve averages the orange event loss and gray nonevent loss with weights and . Its minimum is at , while both endpoint limits diverge because both outcomes have positive probability. These are calculated expectations, rather than measurements. Details.
For conditionally independent binary labels, the likelihood is
Maximizing it is equivalent to minimizing its negative log-likelihood, the mean binary cross-entropy:
It is the loss implied by a Bernoulli distribution for each target, penalizes confident errors strongly and is convex in the linear-logistic parameters. For numerical stability, each contribution can be evaluated as using a stable softplus implementation.
The 10:90 class imbalance does not invalidate this likelihood. Class weighting or resampling may be useful if errors have unequal costs, but changes the training objective and potentially the interpretation of fitted probabilities. Optional ridge regression adds , usually excluding the intercept, to control overly large weights or complete separation.
The printed PDF has a plus sign before the second logarithm. Differentiating that expression literally, with and , gives
For example, at it is , so minimizing this printed objective pushes the predicted probability of class one upwards rather than downwards; the objective is unbounded below as . It is therefore not the usual binary cross-entropy.
If the second sign was intended to be negative, the standard negative log-likelihood is and the derivative simplifies instead to . Stating both cases preserves the actual question's algebra while identifying the apparent sign error. The logarithms here are natural; another base multiplies the gradients by its constant conversion factor.