All problems
Poisson Regression IRLS Step
Problem
Run one IRLS step for Poisson regression with a log link.
For each observation compute mu_i = exp(w * x_i), working response z_i = w * x_i + (y_i - mu_i) / mu_i, and weight W_i = mu_i. Return sum(W_i * x_i * z_i) / sum(W_i * x_i ** 2), or w when the denominator is zero.
Hint
For a log link the IRLS weights equal the Poisson means.
Test cases
case 1
in: [0,[1,2],[1,2]]
expected: 0.4
case 2
in: [0.5,[1,2],[1,3]]
expected: 0.49318911045422326
case 3
in: [-1,[1],[1]]
expected: 0.7182818284590451
Starter codePython
def poisson_irls_step(w, X, y):
# Your code here
pass3 test cases · run your code against them in the editor