2.2.10 · D3Linear & Logistic Regression

Worked examples — Log-loss - binary cross-entropy

2,282 words10 min readBack to topic

The scenario matrix

Every log-loss situation is one cell in this table. The columns are the model's prediction; the rows are the true label. The extra rows below are the special/degenerate/word cases.

Case class What makes it special Example #
, high (correct + confident) best case, loss near 0 Ex 1
, low (wrong + confident) punished, loss large Ex 2
, low (correct + confident) mirror of Ex 1, uses the other term Ex 3a
, high (wrong + confident) mirror of Ex 2 Ex 3b
(maximally unsure) baseline, same loss for either label Ex 4
Full batch (average of many single losses) how single losses combine into one number Ex 5
Degenerate or limiting behaviour, NaN danger, clipping Ex 6
Real-world word problem translate a story into Ex 7
Exam twist: vs , and a gradient units + the update Ex 8

The figure below plots the two "surviving-term" curves so you can see every cell before we compute it.

Figure — Log-loss  -  binary cross-entropy
Figure s01 — two chalk curves on a dark board. The blue curve rises from at the right () to at the left (): this is the loss when the truth is . The pink curve is its mirror, rising to at the right: the loss when . A yellow dashed line marks the baseline, and the two curves cross there at . Labelled dots mark the Ex 1, Ex 2 and Ex 3b heights.


The worked examples


Forecast-then-Verify recap

Recall Across all cells, which single number is the "pass/fail line"?

nats (or bit). A batch loss below it means your model beats random guessing; above it means it's worse than a coin flip.

Recall Why did Ex 2 hurt ~58× more than Ex 1 rewarded, even though the prediction was equally "confident"?

The loss curve is not symmetric: near it flattens toward , but near it rockets to . Confident-and-wrong is punished on the steep side. See the blue curve in the figure.


Connections