All problems
Logistic Coordinate Step
Problem
Take one gradient step for logistic regression on a single feature.
With p = 1 / (1 + exp(-w * x)) and grad = (p - y) * x, return w - lr * grad. The label y is 0 or 1.
Hint
The logistic gradient is (p - y) * x.
Test cases
case 1
in: [0,1,1,0.5]
expected: 0.25
case 2
in: [1,2,0,0.1]
expected: 0.8238405844044235
case 3
in: [-1,1,1,0.2]
expected: -0.853788284273999
case 4
in: [0.5,0,1,0.5]
expected: 0.5
Starter codePython
def logistic_coordinate_step(w, x, y, lr):
# Your code here
pass4 test cases · run your code against them in the editor