TorchedUp
LearnBetaProblemsSystem DesignSoonPremium
TorchedUp
LearnBetaProblemsSystem DesignSoonPremium
←

18. L2 Regularization

Easy

Implement the L2 regularization penalty term.

Signature: def l2_reg(w: np.ndarray, lam: float) -> float

Return lam * sum(w^2).

Math

LL2​=λi∑​wi2​

Asked at

Python 30/10 runs today

Output

Anything you print() in your code will show up here after you click Run.

Test Results

○basic
○zero weights
○large lambda🔒 Premium
○L2 penalty is non-negative
○L2 penalty is non-negative (negative weights only)
○L2 invariant to sign of weights