Given the objective function $$\text{argmin}_{c}(\Vert y - Xc \Vert_2^2 + \lambda\Vert c \Vert_1)$$
by taking the derivate $$\frac{\partial}{\partial c}(\Vert y - Xc \Vert_2^2 + \lambda\Vert c \Vert_1)$$
it can be proved, $\lambda_{\min} = \max|\sum_{j}y^TX_j|$ is the smallest $\lambda$ that makes the solution to the objective a zero vector.
However, when I did it in practice, I found this $\lambda_{\min}$ is not the smallest, here is my code:
x_1 = np.linspace(-1, 1, 30)
x_2 = 2 * x_1 + 0.01 * np.random.rand(30)
x_3 = np.random.uniform(-1, 1, 30)
y = 0.1 * x_1 + 0.5 * x_2
l1 = abs(np.inner(x_1, y))
l2 = abs(np.inner(x_2, y))
l3 = abs(np.inner(x_3, y))
lambda_min = max(l1, l2, l3)
x = np.ones((30, 3))
x[:, 0], x[:, 1], x[:, 2] = x_1, x_2, x_3
lambda_n = lambda_min
while True:
lambda_n = lambda_n * 0.95
lasso_test = Lasso(alpha=lambda_n, fit_intercept=False)
lasso_test.fit(x, y)
temp = lasso_test.coef_
if np.sum(temp) != 0:
print('lambda_n = ', lambda_n)
break
print('lambda_min = ', lambda_min)
lambda_min
is far greater than lambda_n
which is the smallest lambda
that makes lasso_test.coef_
a zero vector.
It is only when I change
lambda_min = max(l1, l2, l3) / 30 # number of examples
will lambda_min
and lambda_n
be the same.
Given this, the formula for calculating $\lambda_{\min}$ should be $$\frac{1}{N}\max|\sum_{j}y^TX_j|$$
I believe there is nothing wrong with the theory, then what is wrong with my code?