Curvingo · Made in India

Glossary

Select one of the keywords on the left…

Logistic RegressionScoring Our Model

Reading time: ~10 min

In the last chapter we scored lines with the mean squared error. For a model that gives chances, we use a score called log-loss (also known as binary cross-entropy). Its rule is simple: for each student, the model pays a penalty of

-\ln(\text{the chance it gave to what really happened})

A model that was right and sure pays almost nothing. A model that was wrong and sure pays a lot. Drag along the curve and complete the three missions.

The Log-Loss Formula

Three students, and the chance of passing the model gave each of them (\ln 0.9 \approx -0.11, \ln 0.5 \approx -0.69, \ln 0.1 \approx -2.30):

StudentWhat happenedChance of passingChance given to what happenedPenalty
Amanpassed0.90.90.11
Belapassed0.50.5
Chiragfailed0.92.30

Chirag failed, but the model was 90 % sure he would pass — so it pays the biggest penalty. The log-loss is the average penalty: (0.11 + 0.69 + 2.30) \div 3 \approx .

Log-loss

For n examples with true labels y_i (1 or 0) and predicted chances p_i,

\text{log-loss} = -\dfrac{1}{n} \sum_{i=1}^{n} \Big[ y_i \ln p_i + (1 - y_i) \ln (1 - p_i) \Big]

When y_i = 1 only the first term survives; when y_i = 0 only the second. That is exactly "the chance given to what really happened".

So during training, the model should

make the log-loss as small as possible
make the log-loss as large as possible
keep the log-loss at exactly 1

Tip

Why not use MSE again? With chances between 0 and 1, the squared error can never be bigger than 1, so a model that is 99 % sure and wrong gets off lightly. Log-loss has no upper limit: being confidently wrong is punished hard, which is exactly what we want.

Speed Round: Who Pays More?

Get five right to move on.

Sina