The input z can be any raw score. The output is always a probability.
Lesson 0013 · Homework 1, Problem 2
Log loss and gradient descent
Six pictures: squeeze a score, price a guess, step downhill, separate accuracy from loss, see why β runs away, then add the regularization wall.
The machine
One row through the calculator.
No mystery machine first: pick one high-school-number row, turn the β dial, multiply, squash, price the guess, then step the dial downhill.
1. Sigmoid
Same button. Three raw scores.
Call the raw score z = βx. Put any z into the sigmoid calculator. Big negative becomes almost 0. Zero becomes exactly .5. Big positive becomes almost 1.
2. Log loss
MSE's cousin for categories.
One training row has an input x_i and a known answer y_i. The model does not output three separate predictions; it outputs one probability list for the possible labels.
Before gradient descent
Learning means changing beta.
The row does not change. The human knobs do not change during this run. The model learns by changing its beta values, then recomputing the prediction for the same row.
Same input, new model: x_i = 3 stays fixed, β1 changes from 2.00 to 2.10, so the prediction changes from σ(5.00)=.993 to σ(5.30)=.995.
3. Gradient descent
How does the model know which way to change beta?
The goal is not to move for its own sake. The goal is to lower log loss. Gradient descent is the rule that tells beta which direction to move next.
Purpose: log loss tells the model how bad the current beta is. Gradient descent uses the slope of that loss to choose the next beta. Then the same rows are predicted again with the new beta.
4. Accuracy is not loss
One scoreboard can say perfect while another still moves.
Accuracy counts threshold decisions. Log loss keeps caring about the probability margin. Training accuracy also says nothing by itself about new data.
5. Separated data
Perfect separation makes a downhill road with no floor.
When every negative x has y=0 and every positive x has y=1, bigger β keeps making every probability more confident and still correct. Plain log loss keeps decreasing; β keeps running.
6. Regularization
Add a wall so the valley has a real bottom.
λβ² is a spring attached to the β dial. Pull β too far and the spring pulls back. The combined objective has a finite minimum.
learned directly by gradient descent
chosen outside training with validation data
Homework map
Use the same pictures on the assigned four points.
The demo used (-3,0), (-1,0), (1,1), (3,1). Homework 1 uses (-2,0), (-1,0), (1,1), (2,1). Same machine; different arithmetic.
Check
Three small locks.
Answer from memory before checking.