Signals to learning / 6. Learn from data

Lesson 23 of 40 · Intermediate · About 30 minutes

Classification and cross-entropy

Why penalise a confidently wrong prediction so strongly?

You will be able to

  • Convert a binary logit into probability.
  • Calculate binary cross-entropy and distinguish probability from a decision threshold.

A score becomes a probability

A binary model can output a real-valued logit z. The sigmoid maps z to p, interpreted as the model probability of class 1. A chosen threshold turns probability into a decision; changing threshold changes false-positive/false-negative trade-offs, not the fitted probability itself.

A loss that sees confidence

For y in {0,1}, binary cross-entropy is −y log p−(1−y) log(1−p). Natural logarithms produce loss in nats. A confidently wrong prediction incurs a large loss. Stable implementations operate on logits to avoid taking logs of probabilities rounded to zero or one.

p=1/(1+e⁻ᶻ); BCE=−y log p−(1−y)log(1−p)

Worked example

At z=0, p=0.5 and either target gives loss ln 2≈0.693. For y=1, p=0.9 gives loss≈0.105, whereas p=0.1 gives≈2.303.

A common trap

A probability of 0.9 is not proof the model is calibrated; that must be assessed across relevant held-out outcomes.

Predict, then experiment

For target 1, does increasing the logit raise or lower the loss? Before touching the controls, say or write your prediction.

Try it yourself

From a logit to probability

How does confidence affect cross-entropy?

Curve is sigmoid(z). The circle marks the adjustable logit; target is 0 or 1. Binary cross-entropy uses natural logarithms and a numerically stable logit formula.

Your experiment

Set target 1 and compare logits −4,0,+4. Repeat for target 0. Observe the same probability curve but a different loss for the changed label.

Change one parameter at a time. Compare what you observed with your prediction and record an explanation in your notes.

Check your understanding

Try from memory first. Hints and feedback are part of learning, not a penalty. These checks are for self-study, not a graded qualification.

1. Changing a classification threshold changes…
Give me a hint

Separate scoring from acting.

2. What probability does sigmoid(0) produce?

Accepted absolute tolerance: ±0.001 .

Give me a hint

exp(0)=1.

Reference answers (after your attempt)
  1. the decision policy — Correct: the same scores can produce different decisions.
  2. 0.5 — 1/(1+exp(0))=1/2.

Apply it: Choose a decision threshold responsibly

Use paper, your notes, or a local notebook/editor. Code examples are Python 3 starting points to run yourself; this page does not execute code or automatically assess the practical task.

  1. Name a binary task and the cost of each error type.
  2. Describe how to select a threshold on validation data.
  3. Specify a held-out calibration and decision-metric check.
Reference solution & review criteria

For costly false negatives, a lower threshold may increase recall at the cost of more false positives. Select by an explicit validation objective, then report held-out confusion counts and calibration; avoid tuning on final test results.

Your notebook

Notes and progress stay in this browser. They are not sent to the server; ordinary web-server request logs still operate. Export a backup from the course page.

Review list

Completion requires both correct checks and your practical-task acknowledgement.

Go deeper

Sources support further study; the worked examples and questions here are original. Browser experiments are small, disclosed models—not evidence of production-model quality or hardware performance.