Metrics ยท Easy
Log Loss
Evaluate probabilistic predictions with numerical stability.
Task
Implement logloss(labels: list[int], probabilities: list[float]) -> float. Compute the mean negative log-likelihood of binary labels under predicted probabilities.
Requirements
- Clip every probability to [1e-15, 1 - 1e-15] before taking logarithms.
- Use the natural logarithm.
- Return 0.0 for empty inputs.
- Inputs have equal length and labels are binary.
Example
labels = [1, 0]
probabilities = [0.9, 0.2]
logloss(labels, probabilities)
# 0.1642520335