Skip to content
DeepForgeby svx
All problems
MediumOptimizationop-121

IRLS One Step

Problem

Run one IRLS (Fisher scoring) step for logistic regression.

For each observation compute p_i = sigmoid(w * x_i), weight W_i = p_i * (1 - p_i), and working response z_i = w * x_i + (y_i - p_i) / W_i. Return sum(W_i * x_i * z_i) / sum(W_i * x_i ** 2); skip zero-weight observations and return w when the denominator is zero.

Hint

IRLS reweights each observation by the logistic variance p(1 - p).

Test cases

case 1
in: [0,[1,2],[1,1]]
expected: 1.2
case 2
in: [0.5,[1,2,3],[1,0,1]]
expected: 0.2726936091248113
case 3
in: [1,[1],[0]]
expected: -2.7182818284590455
Starter codePython
def irls_step(w, X, y):
    # Your code here
    pass

3 test cases · run your code against them in the editor