Question: We wish to visualize the relation between the lines l , l ' in Problem 2 . Fill Blanks ( 1 ) and ( 2

We wish to visualize the relation between the lines l,l' in Problem 2. Fill Blanks
(1) and (2) below and draw the graph.
def min_sq(x,y): # function for finding the intercept and coefficient of
the least-squares
x_bar,y_bar=np.mean (x),np.mean(y)
beta_l=np.dot (x-x_bar,y-y_bar)/np.linalg.norm (x-x_bar)**2
beta_0=y_bar-beta__1*x_bar
return [b]eta_1,beta__0]
N}=10
a=np.random.normal(loc=2,scale=1) # mean, variance, size
b=randn(1) # coefficient
x=randn (N)
y=a*x+b+randn(N)
al,bl=min_sq(x,y) # estimating
xxx=x-# blangk(1) #
yY=y-# blank(2) #
a2,b2=min_sq(xxx,yy) # estimating after centering
(1.7865393047324676,1.067565008452225e-16)
x_seq=np.arange (-5,5,0.1)
y_pre=x_seq*a1+b1
yY_pre=x_seq*a2+b2
plt.scatter(x,y,c="black")
plt.axhline (y=0,c="black", 1inewidth=0.5)
plt.axvline ( x=0,c="black", linewidth=0.5)
plt.plot(x_seq,y_pre,c="blue", label="before_centering")
plt.plot (x_seq, yy_pre, c="orange", label="after_centering")
plt.legend(1oc="upper,left")
We wish to visualize the relation between the

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!