Skip to content
DeepForgeby svx
All problems
MediumML Fundamentalsml-163

Regularized Logistic Step

Problem

Perform one gradient descent step for L2-regularized logistic regression without an intercept: w = w - lr * ((1/n) * X^T (sigmoid(Xw) - y) + lam * w).

Return the new weight list; empty X returns a copy of w.

Hint

The L2 term contributes lam * w to the gradient, shrinking weights toward zero.

Test cases

case 1
in: [[[1],[2]],[0,1],[0],0.1,0.1]
expected: [0.025]
case 2
in: [[[1],[2]],[1,1],[0],0.5,0]
expected: [0.375]
case 3
in: [[[1]],[1],[1],0.1,0.1]
expected: [1.0168941421369995]
case 4
in: [[],[],[1,2],0.1,0.1]
expected: [1,2]
Starter codePython
import math
def regularized_logistic_step(X, y, w, lr, lam):
    # Your code here
    pass

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