Learning objectives
- Calculate binary logarithmic loss and compare forecasts with identical classifications.
- Explain why assigning near-zero probability to an outcome can be costly.
Prerequisites: Use natural logarithms and probabilities strictly between zero and one.
Mechanism and interpretation
For a binary outcome y and forecast probability p of y=1, logarithmic loss is −[y ln(p)+(1−y)ln(1−p)]. Average this value across observations; smaller loss is better. Natural logarithms express the score in nats, not currency. The score rewards allocating probability to what occurs, so two models with the same above-50% classifications can receive different scores because their confidence differs.
The loss becomes very large when a model assigns tiny probability to an outcome that occurs. Assigning zero probability to the realized outcome gives infinite mathematical loss. Software may clip probabilities to a numerical bound; that implementation choice should be recorded rather than interpreted as a substantive belief that the outcome was impossible. Log loss evaluates probability forecasts and does not directly measure a trading strategy’s returns, costs or position sizing.
Worked case · synthetic data
Four hypothetical outcomes are 1, 1, 1, 0. A model predicts p=0.9 every time. Its mean loss is −[3 ln(0.9)+ln(0.1)]/4≈0.6547. A second model predicts p=0.75 throughout, giving loss −[3 ln(0.75)+ln(0.25)]/4≈0.5623. Both classify every observation as positive at a 0.5 threshold and achieve 75% accuracy, yet the less confident probability forecast scores better on this sample. This comparison uses fixed supplied forecasts; it does not validate fitting 0.75 on these same outcomes.
Failure modes and context
A small evaluation sample can produce unstable rankings. Calibration, class prevalence and the intended decision problem still matter. Comparing models after extensive tuning on the same outcomes creates selection bias, and class weighting changes the target distribution represented by the score. Report whether the loss is an average or sum, its logarithm base, the positive label and any clipping convention so that numbers from different pipelines are comparable.
Practice assignment
Two new forecasts are p=0.8 and p=0.4, with observed outcomes 1 and 0. Calculate each natural-log loss and their mean. Then explain why replacing the second probability by 0.9 worsens its loss even though the first forecast remains unchanged.
Worked answer
The losses are −ln(0.8)≈0.2231 and −ln(0.6)≈0.5108, averaging about 0.3670. For the second realized zero, a forecast p=0.9 leaves probability 0.1 for what occurred, giving −ln(0.1)≈2.3026. The score penalizes that unsupported confidence; it does not infer a monetary loss from the number 2.3026.
Check your understanding
Question 1
What logarithm convention is used?
- No logarithm
- Natural logarithm
- Base ten without conversion
Reveal answer and reasoning
B. Natural logarithm
The loss is defined using ln and reported in nats.
Question 2
Why do the two worked models have equal classification accuracy?
- Both always exceed the 0.5 positive threshold
- Their probabilities are identical
- Both have zero log loss
Reveal answer and reasoning
A. Both always exceed the 0.5 positive threshold
Their class decisions match even though their probability confidence differs.
Question 3
What happens mathematically if an occurred outcome had probability zero?
- Log loss is zero
- Accuracy becomes undefined for every observation
- Log loss is infinite
Reveal answer and reasoning
C. Log loss is infinite
The negative logarithm diverges as the assigned probability approaches zero.
