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))Think before coding
Correct confident probabilities have low loss, while confident mistakes have high loss. Clipping prevents log(0) and preserves finite comparisons. The average makes losses comparable across equally defined datasets of different sizes. Work through the example by hand before changing the starter. Decide what should happen for an empty input, a single value and a repeated value where those cases apply. The checks use several inputs so a hard-coded answer cannot stand in for the rule.
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.
The explanation opens here once every check passes.