For a square matrix of random data, N columns and N rows. I am fitting two models, linear regression and Lasso.
For the linear regression, I achieve a perfect score in train set, while in the Lasso I achieve a score of 0.
import pandas as pd
import numpy as np
from sklearn import linear_model
N = 100
X = pd.DataFrame(np.random.rand(N,N))
y = np.random.randint(20, size=N)
lin = linear_model.LinearRegression().fit(X,y)
lasso = linear_model.Lasso().fit(X,y)
print('Linear regression score',lin.score(X,y))
print('Lasso score',lasso.score(X,y))
Linear regression score 1.0
Lasso score 0.0 My questions will be:
Can someone give me an intuitive idea why for a square matrix, Lasso regression achieve different results from Linear regression?
What is the intuition behind the Lasso shrinking?
Note: In this case, the matrix is squared and the data/target is created randomly.