Skip to content

Log Loss (Cross-Entropy)

The standard loss and metric for probabilistic classifiers: it heavily punishes confident wrong answers and rewards well-calibrated probabilities.

Also cross-entropy loss · binary cross-entropy · categorical cross-entropy · negative log-likelihood · NLL

Domain 01
Foundations
Role · kind
Evaluating and testingMetric
Level
Intermediate

A quiz where you bet on your answers. Saying 'I'm 99% sure' and being wrong costs you a fortune. Saying '60% sure' and being wrong costs a little. You learn to be honest about how sure you are.

Where it fits

+All relationships as a list

See it on the full map

How it works

Accuracy only checks whether the top answer was right. Log loss also looks at how confident the model was.

For each example, take the probability the model gave to the correct class, pp, and compute −log⁡p-\log p:

Probability on the right answerLoss
0.990.01
0.90.11
0.50.69
0.12.30
0.014.61

A confident wrong answer is punished far more than a hesitant one. The best strategy is to be honest: say 70% when you are right 70% of the time.

It is the default loss function for classification: logistic regression, image classifiers and language models all minimize it. For language models, averaging it over every token and taking the exponent gives perplexity.

The math

For NN examples with true classes yiy_i and predicted distributions pip_i,

L=−1N∑i=1Nlog⁡pi(yi).\mathcal{L} = -\frac{1}{N} \sum_{i=1}^{N} \log p_i(y_i).

This is the negative log-likelihood of the labels, so minimizing it is maximum likelihood estimation. See probability basics.

Everyday use cases

  • Case 01

    Training classifiers

    Logistic regression, image classifiers and LLMs are all trained by minimizing cross-entropy.

  • Case 02

    Forecasting competitions

    Rain forecasts and prediction markets are scored with log loss so forecasters cannot fake confidence.

Strengths, weaknesses and when to use it

Strengths

  • Rewards calibrated probabilities, not just correct labels.
  • Smooth and well suited to gradient descent.

Weaknesses

  • A single confident mistake can dominate the average; very sensitive to label noise.
  • Hard to interpret on its own; compare against a baseline.

When to use itAs the training loss for classification and as an evaluation metric when probability quality matters.

Compare with

Check yourself

  1. Q01

    The true class is A. Which prediction has the higher log loss?

    Show answer

    C: P(A) = 0.01

  2. Q02

    How is perplexity related to cross-entropy?

    Show answer

    A: It is the exponent of the average cross-entropy

Go deeper