AI Glossary / Statistics and probability / Advanced

Binary cross-entropy

Definition

Binary cross-entropy, often abbreviated BCE, is a loss function for assessing predicted probabilities of a binary outcome. For an observed label y equal to zero or one and predicted probability p of label one, it is -[y log p + (1-y) log(1-p)]. It assigns a small loss when the observed outcome receives high probability and a large loss when it receives very low probability.

What it means

BCE evaluates the probability assigned to what actually happened, rather than only whether a prediction crossed a classification threshold. Two models can make identical yes-or-no decisions yet receive different losses because their confidence differs.
For a positive outcome, the loss reduces to -log p. For a negative outcome, it reduces to -log(1-p). The same logic applies in both cases: score the probability of the observed label. BCE is also the negative log-likelihood contribution of a Bernoulli observation. A lower average loss on comparable evaluation data indicates better performance under this particular probability-scoring rule.

How it works

Compute one loss for each labeled observation, then use a stated reduction such as the mean or sum. Natural logarithms express the result in nats; another logarithm base changes the numerical scale. Sample or class weighting changes the contributions and must be documented when comparing results.
Training minimizes a version of this objective over model parameters. Evaluation applies it to predictions on data not used for fitting. Inputs must be interpreted consistently: p denotes the probability of the class encoded as one, not a raw unconstrained score.
Assigning zero probability to an outcome that occurs gives infinite mathematical loss. Software may use clipping or numerically stable calculations to avoid numerical problems. Such implementation choices should not be confused with changing an observed label or establishing that an impossible prediction was reasonable.

Three practical examples

  • Response prediction: an analyst evaluates probabilities that users respond to a message, retaining more information than a thresholded response/no-response score.
  • Quality classification: a team compares probability forecasts for whether a simulated item meets a binary criterion, checking highly confident errors separately.
  • Model monitoring: analysts track average loss on newly labeled observations alongside class proportions and decision metrics, investigating whether a shift reflects worse forecasts or a changed evaluation population.

Think of it this way

Imagine charging a forecaster according to how surprising the observed outcome was under their prediction. An outcome assigned probability 0.9 is unsurprising and receives a small charge. An outcome assigned probability 0.01 is highly surprising and receives a much larger charge.

Worked example

Consider an original evaluation set of four observations with labels 1, 0, 1 and 0. Model A predicts probabilities of label one of 0.8, 0.2, 0.4 and 0.1. Use natural logarithms and an unweighted mean.
For the first observation, loss is -log(0.8), approximately 0.2231. For the second, it is -log(1-0.2), again 0.2231. For the third, the positive label receives probability 0.4, giving -log(0.4), approximately 0.9163. For the fourth, loss is -log(1-0.1), approximately 0.1054.
The sum is approximately 1.4679, and the mean BCE is 1.4679/4, approximately 0.3670. Using a threshold of 0.5 produces predictions 1, 0, 0 and 0, so accuracy is three correct observations out of four, or 75 percent.
Now consider Model B, which predicts 0.99, 0.01, 0.01 and 0.01. It makes exactly the same thresholded predictions and also has 75 percent accuracy. Its losses are approximately 0.0101, 0.0101, 4.6052 and 0.0101. The mean is approximately 1.1588, substantially worse than Model A's 0.3670.
Model B is more confident on the three correct cases, but it assigns only one percent probability to the positive outcome in the third case. That confident error outweighs the improvements on the other three observations under BCE. This is a scoring comparison on the supplied data, not proof that one model will always perform better in future use.
A constant prediction of 0.5 would give loss -log(0.5), approximately 0.6931, on every observation. Model A beats that baseline on this small set, while Model B does not. The baseline is a useful arithmetic reference, not necessarily the appropriate baseline for a population with unequal class frequencies.
If Model A changed only its third probability from 0.4 to 0.49, the thresholded decision would remain negative. However, the third loss would fall from approximately 0.9163 to 0.7133 because the observed positive outcome received more probability. BCE can therefore detect a probability improvement that accuracy does not register.
All values are rounded displays of direct logarithmic calculations.

Illustrative case study

Fictional company Birch Forecasting compares two probability models on held-out simulated responses. Its analysts initially see identical accuracy and then inspect BCE and individual losses. They find that a small group of confident errors accounts for a large difference.
Before choosing a model, the team checks whether labels are reliable, whether class frequencies changed and how probabilities behave across relevant subgroups. It also evaluates the consequences of its chosen decision threshold separately. This fictional workflow reports no measured business gain or deployed result.

Common misconceptions and mistakes

BCE is not one minus accuracy and is not limited to the interval from zero to one. A sufficiently confident wrong prediction can produce an arbitrarily large mathematical loss.
Another mistake is feeding hard class decisions into a metric intended to assess probabilities. Confusing the positive-class encoding can also reverse the interpretation of p. A lower empirical BCE does not by itself prove perfect calibration, eliminate sampling uncertainty or guarantee lower business costs. Weighted and unweighted losses, or summed and averaged losses, should not be compared as though they were identical quantities.

Business use

BCE helps teams assess probability forecasts used for ranking, planning or thresholded decisions. Reports should identify the evaluation population, positive label, weighting and aggregation convention. Pair it with decision measures relevant to the actual application, since probability scoring and the cost of an action answer different questions.

People also ask

Can BCE exceed one?

Yes; the confidently wrong example has loss about 4.6052.

Does changing a threshold change BCE?

Not when the underlying probabilities remain unchanged.

Is zero always achievable on future data?

No; outcomes may be uncertain and the model imperfect.

Check your understanding

Why did both models have identical accuracy?

Answer: Their probabilities crossed the same side of the threshold.

Why was Model B's loss worse?

Answer: It was extremely confident about the wrong third outcome.

Why did 0.49 improve the third loss?

Answer: It assigned more probability to the observed positive label.

Related terms

  • Cross-entropy
  • Log Loss
  • Logistic regression
  • Probability calibration
  • Brier score
  • Classification threshold
  • Bernoulli likelihood

Learn next

Compare BCE with the Brier score on the same four predictions and inspect how each responds to confident errors.

  • Brier score

More in Statistics and probability

  • Between-group design experiment - A between-group design experiment compares outcomes from separate groups exposed to different experimental conditions.
  • Between­subjects designs - Between-subjects designs are study arrangements in which different participants experience the different levels of a factor.
  • Bimodal - Bimodal describes a distribution with two distinct peaks, or modes. Values tend to concentrate around two regions rather than one.
  • Binary regression - Binary regression models the relationship between explanatory variables and an outcome with two possible values, commonly encoded as zero and one.
  • Binomial distribution - The binomial distribution describes the number of successes in a fixed number of independent trials when each trial has two possible outcomes and the same...
  • Binomial test - A binomial test assesses a specified probability of success using a count of successes in a fixed number of independent binary trials with a common success...

Sources

Aalto Dictionary of Machine Learning, binary cross-entropy entry: https://aaltodictionaryofml.github.io/ADictML_Main.pdf . Scikit-learn, log_loss definition and conventions: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.log_loss.html . The prediction tables and company scenario are original illustrations.

Previous: Binary constraint Next: Binary decision

  • Home
  • Daily AI Updates
  • Blog
  • AIFBL Academy
  • AI Glossary
  • Products and Tools
  • Store
  • Free CFO AI Prompt Pack
  • About Shihan Sheriff
  • Privacy Policy
  • Terms of Use
  • Refund Policy
  • Cookie Policy
  • Earnings Disclaimer