Compare L1 and L2 penalty terms
Check signs and decimal points before moving to the next value. · 198 words
A penalty term adds a cost during training to discourage unnecessarily large weights. In a linear model, each weight w_j multiplies one input feature. L1 regularization adds lambda * sum |w_j|, where lambda >= 0 sets the strength. For weights (0.8, -0.2, 0), its penalty is lambda(0.8 + 0.2 + 0) = lambda. The absolute value penalty has a corner at zero, so an optimum can place a weight exactly at zero. The zero weight then removes that feature's contribution to prediction. This creates a sparse model: one with few nonzero weights, which can be easier to interpret.
L2 regularization adds lambda * sum w_j^2. For weights (3, -1), the penalty is lambda(9 + 1) = 10 times lambda. The difference appears in the gradient, which tells the optimizer how to change each weight. L1 has gradient lambda sign(w_j), a constant push for every nonzero weight. L2 has gradient 2lambda w_j, so large weights receive stronger pushes. With lambda = 0.1 and a learning rate of 0.01, the size of one update, a weight of 3 falls by 0.001 under L1 but 0.006 under L2, ignoring the data-loss gradient. L1 favors removing features; L2 smoothly shrinks all weights.
Check your recall
For weights (0.8, -0.2, 0), what is the L1 penalty, and what useful property can L1 create?
Check your answer
The L1 penalty is lambda. It can set irrelevant weights to exactly zero, creating a sparse model with only a few nonzero weights.
Sources and credits
Original KeyTouch lesson. Background reading · Google · Linear regression.