Logistic Regression
Medium
Binary Cross-Entropy Loss
Medium
~15 min
code completion
Binary Cross-Entropy Loss
For binary classification, the standard loss is binary cross-entropy (log loss):
where:
Intuition:
Your task:
Implement binary_cross_entropy(y_true, y_pred). Assume all y_pred values are strictly in (0, 1).
Example Tests
Mixed predictions, standard case
Input: {"y_pred":[0.9,0.1,0.8,0.2],"y_true":[1,0,1,0]}
Expected: 0.16425
Perfect confidence on correct label
Input: {"y_pred":[0.5],"y_true":[1]}
Expected: 0.69315
All correct with high confidence: low loss
Input: {"y_pred":[0.99,0.99,0.01,0.01],"y_true":[1,1,0,0]}
Expected: 0.01005