All problems
Second Derivative of Cross-Entropy
Problem
For the binary cross-entropy as a function of the predicted probability p, L(p) = -y log(p) - (1 - y) log(1 - p) with y in {0, 1}, the second derivative is y / p^2 + (1 - y) / (1 - p)^2.
Given y and p with 0 < p < 1, return L''(p).
Hint
The curvature is positive everywhere, so cross-entropy is convex in p.
Test cases
case 1
in: [1,0.5]
expected: 4
case 2
in: [0,0.5]
expected: 4
case 3
in: [1,0.25]
expected: 16
case 4
in: [0,0.8]
expected: 25
Starter codePython
def second_derivative_cross_entropy(y, p):
# Your code here
pass4 test cases · run your code against them in the editor