PythiloLesson 3 of 8 · progress kept in this browser

Keep binary log loss finite

Log loss measures the probability assigned to the correct binary outcome. Taking log of zero is undefined, while extreme confident errors should produce a large penalty. Clip predicted probabilities to a small open interval before applying logarithms. This numerical safeguard does not make an incorrect probability well calibrated; it only gives the computation a defined finite result.

import math
p = 0.8
print(-math.log(p))
Your task

Write log_loss(labels, probabilities). Inputs are equal-length nonempty sequences, labels are 0/1. Clip each probability to [1e-12, 1-1e-12], return mean binary log loss, and raise ValueError for empty labels.