Question: We perform linear regression analysis with Lasso for the case where Y is the target variable and the variables x 1 , x 2 ,

We perform linear regression analysis with Lasso for the case where Y is the
target variable and the variables x1,x2,x3 and x4,x5,x6 are highly correlated.
We generate N=500 groups of data, distributed as in the relations below, and
then apply linear regression analysis with Lasso to xinRNp,yinRN.
z1,z2,lon,lon1,dots,lon6N(0,1)
{xj:=z1+lonj5,j=1,2,3
xj:=z2+lonj5,j=4,5,6
y:=3z1-1.5z2+2lon
Fill in the blanks (1),(2) below. Plot a graph showing how each coefficient
changes with . n =500
x = np.zeros((n,6))
z = np.zeros((n,5))
for k in range(2):
z[:, k]= np.random.randn(n)
y = ## Blank (1) ##
for j in range(3):
x[:, j]= z[:,0]+ np.random.randn(n)/5
for j in range(3,6):
x[:, j]= z[:,1]+ np.random.randn(n)/5
lambda_seq = np.arange(0.1,20,0.1)
p =6
r = len(lambda_seq)
coef_seq = np.zeros((r, p))
cols =["blue", "red", "green", "yellou", "purple", "orange"]
for i in range(r):
coef_seq[i, :]._= ## Blank(2) ##
for j in range(p):
plt.plot(-np.log(lambda_seq), coef_seq[:, j]+0.01* j.
c=cols[j], label="X"+str(j+1))
plt.ylabel(r"")
plt.legend(loc="upper |left")
plt.title("Lasso")
We perform linear regression analysis with Lasso

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!