Geometric Intuition of how sign(𝑤ⱼ) aligns with sign(z) in Lasso Regression
3498 words18 min read
Authors
Name
Vishal Mandrai
Twitter
In this post, we'll see the geometric intuition of how sign(wj) aligns with sign(z) in Lasso Regression. This is an important detail that arise while deriving the optimal solution for Lasso Regression via Coordinate Descent based optimization. Their comes a defining point where solution turns to Soft Thresholding Operation for calculating optimal wj, because sign(wj) aligns with sign(z).
For better understanding take a quick look at Lasso derivation. Click to read.
Let's refresh our memory and start with a quick recap of Lasso Regression derivation.
Now, differentiate L(w) w.r.t wj keeping other coefficients fixed. Then, find the value of wj for which the derivative is zero. The final equation be:
wj=n1i=1∑n(yi−Xi−jw−j)Xij−λsign(wj)
NOTE: Here we know, sign of wj is the same as the sign of n1∑i=1n(yi−Xi−jw−j)Xij (when wj=0). Its time to see 'how'.
The above equation finally becomes a “Soft Thresholding Operation” due to this knowledge.
From the above discussed derivation, we can draw an important insight about z - correlation between input featureXj and the residuals.
Let's say we are in p+2dimensional space where p+1 dimensions mark all coefficients of Lasso Regression and p+2th dimension marks the Loss (without L1-penalty term). We plot our Loss Function in this space:
Now we know, what exactly z represents. Knowing the sign of z we can predict the sign of updated wj on k+1th iteration. Let’s see how!
How z Determines sign(𝑤ⱼ)
Let’s say we have completed k optimization iterations and w=[w0k,w1k,…,wjk,…,wpk]. Now we are going for k+1th optimization iteration in which we are updating the coefficient wj.
Let's say the slope of the tangent at pointP(w0k,w1k,…,wj−1k,0,wj+1k,…,wpk) on the Loss curve in p+2dimensional space is some negative slope.
∂wj∂(L(w))P=(w0k,w1k,…,wj−1k,0,wj+1k,…,wpk,Loss)=some negative value
That means, −z is −ve and hence z is +ve. The optimal value of wj for which loss be minimum is some positive value at the right-side of 0.
∂wj∂(L(w))P=(w0k,w1k,…,wj−1k,0,wj+1k,…,wpk,Loss)=−z=some negative value
z=some positive value→sign(z)=+ve
Check the below graph. Showing relationship between wj and Loss in 2-D plot:
Similarly, if the slope of the tangent at pointP(w0k,w1k,…,wj−1k,0,wj+1k,…,wpk) on the Loss curve in p+2dimensional space is some positive slope.
∂wj∂(L(w))P=(w0k,w1k,…,wj−1k,0,wj+1k,…,wpk,Loss)=some positive value
That means, −z is +ve and hence z is −ve. The optimal value of wj for which loss be minimum is some negative value at the left-side of 0.
∂wj∂(L(w))P=(w0k,w1k,…,wj−1k,0,wj+1k,…,wpk,Loss)=−z=some positive value
z=some negative value→sign(z)=−ve
NOTE: Irrespective of sign(wj) from kth optimization iteration, sign(wj) after k+1th iteration can be determined by signz.
You see, in both the casessign(z)aligns with the sign of updated wj.
Conclusion: Sign of z dictates the sign of updated wj.
Hence, we can use the sign of z and simplify the equation:
wj=n1i=1∑n(yi−Xi−jw−j)Xij−λsign(wj)
This simplification naturally leads to Soft Thresholding Operation. That is: