Tracks incorrect labelling of the data class by the model and penalizes the model if deviations in probability occur into classifying the labels. Low log loss values equate to high accuracy values when predictions are well calibrated, but log loss punishes confident mistakes more harshly than accuracy alone.
Build better agents with Arize
Trace, evaluate, and learn. Build agents that work with Arize AX and start tracing your runs today.
Prefer open source? Try Arize Phoenix for self-hosted, open source agent observability.
Key takeaways
- Log loss (cross-entropy) measures how well predicted probabilities match true class labels.
- Confident wrong predictions incur large penalties because of the logarithm of probability near zero.
- Lower log loss is better; perfect calibration at the true labels approaches zero loss.
- Log loss rewards calibrated probabilities, not just correct argmax labels at one threshold.
- Track log loss alongside threshold metrics when decisions use probability cuts.
Formula intuition
For binary labels y in {0,1} and predicted probability p of class 1:
Log loss = -[y log(p) + (1-y) log(1-p)]
Multiclass extends with one-hot true class and predicted class probabilities. Predict 0.99 on the wrong class and loss spikes. Predict 0.55 on the wrong class and loss is smaller.
Averaging over rows yields dataset log loss. Compare models on the same eval set with identical label definitions.
Relationship to accuracy
A model can achieve high accuracy at threshold 0.5 while log loss stays poor if probabilities are overconfident on errors.
Conversely, good log loss implies probabilities align with outcomes, which supports threshold tuning and risk ranking.
Use accuracy for hard decisions at a fixed cut; use log loss when scores feed ranking, pricing, or ensemble stacking.
Training connection
Softmax plus cross-entropy is the standard classification training loss. The eval metric mirrors what optimization already pressures, though regularization and class weights change the optimum.
Class imbalance weighting adjusts loss per class; report both weighted training loss and unweighted eval log loss for clarity.
Calibration linkage
Log loss improves when predicted probabilities match empirical frequencies (calibration). After training, check reliability diagrams on validation data.
Platt scaling or isotonic regression can improve calibration without changing argmax accuracy much.
Production monitoring
When labels arrive delayed, track rolling log loss on scored rows with outcomes. Sudden increases may indicate drift or broken calibration even if argmax accuracy is flat.
Slice log loss on critical cohorts; global averages hide subgroup calibration collapse.
Guides on AI model lifecycle management include metric review in promotion gates.
Image classifier deployment posts such as shipping image classification models with confidence emphasize pairing scalar metrics with slice charts.
Probabilistic scorers inside agent routes should log loss components in eval stores covered by LLM and agent evaluation platforms.
Failure modes
Computing log loss with zero probabilities without epsilon clipping breaks numerics.
Mixing label encodings between train and eval silently inflates loss.
Reporting log loss on uncalibrated Platt outputs after threshold-only tuning misleads stakeholders.
Using log loss on imbalanced data without stating class weights confuses comparisons.
Class weights and log loss
Training with class weights changes the loss surface; report unweighted log loss on eval sets for comparability across experiments.
For multilabel problems, aggregate log loss per label and macro-average so rare labels remain visible.
Production dashboards
Plot rolling seven-day log loss beside threshold metrics when probabilities drive ranking decisions. Divergence between the two signals calibration work.
Alert when log loss improves while business KPIs fall; the model may be calibrated on the wrong label definition.
Practitioner checklist
Before changing production settings, confirm labels, thresholds, and monitor windows match the definitions used in your last offline eval. Snapshot dashboards when incidents start so postmortems compare apples to apples.
Run slice-level reviews on high-traffic cohorts weekly even when global metrics look flat. Many failures appear first in one locale, product line, or prompt route.
Document model version, featurizer hash, and data window in every incident ticket. Future you needs that context to interpret drift charts.
When metrics disagree (offline vs online, precision vs recall), write down the business cost of each error type before picking a fix. Metrics are proxies; costs are the decision.
Share eval harness links in release notes so support and PM teams know which golden tasks must pass before they announce improvements.
FAQ
Is log loss the same as cross-entropy?
In classification practice the terms are used interchangeably for the same formula on hard labels.
What is a good log loss value?
Depends on class balance and baseline. Compare to a naive predictor and previous model versions on identical data.
Can log loss be negative?
With proper probabilities in (0,1), per-row loss is non-negative. Implementation bugs or invalid probs can produce anomalies.
Should I optimize threshold using log loss?
Thresholds optimize business metrics (F1, cost). Log loss evaluates probability quality across thresholds.
Does log loss apply to LLM classifiers?
When models emit class probabilities or softmax over label tokens, yes. Pure generative metrics differ.