The standard loss function for **classification** tasks. Measures how well predicted probabilities match the true label.
CE = -Σ y_true[i] × log(y_pred[i])For one-hot y_true this simplifies to:
CE = -log(y_pred[correct_class])cross_entropy([0,1,0], [0.1, 0.8, 0.1]) → 0.22314 # = -log(0.8) = 0.22314
Round to **5 decimal places**.
Similar Problems
Test Cases (2 visible · 2 hidden)
Case 1: Standard case
Input: cross_entropy([0,1,0], [0.1,0.8,0.1])
Expected: 0.22314
Case 2: Confident correct
Input: cross_entropy([1,0,0], [0.9,0.05,0.05])
Expected: 0.10536
⌘↵ Run · ⌘⇧↵ Submit