All problems
Bernoulli NLL Gradient in Probability
Problem
For the Bernoulli negative log-likelihood L(p) = -y log(p) - (1 - y) log(1 - p), the derivative with respect to p is -y / p + (1 - y) / (1 - p).
Given p and y, return the derivative value.
Hint
Differentiate each log separately; one term vanishes depending on y.
Test cases
case 1
in: [0.5,1]
expected: -2
case 2
in: [0.25,0]
expected: 1.3333333333333333
case 3
in: [0.8,1]
expected: -1.25
Starter codePython
def bernoulli_nll_gradient(p, y):
# Your code here
pass3 test cases · run your code against them in the editor