In [40]:
%pylab inline
In [41]:
x = arange(0,30)
In [42]:
x = x.reshape((30,1))
In [43]:
error = np.random.normal(0,15,(30,1))
In [44]:
y = 5*x+2+error
In [45]:
scatter(x,y)
Out[45]:
In [46]:
A = hstack([x, ones_like(x)])
In [47]:
v = linalg.lstsq(A, y)[0]
v
Out[47]:
In [48]:
plot(x,dot(A, v),"r")
scatter(x,y)
Out[48]:
In [49]:
y =3*x**2+15*x+2+error
In [50]:
scatter(x,y)
Out[50]:
In [51]:
A = hstack([x**2,x, ones_like(x)])
In [52]:
v = linalg.lstsq(A, y)[0]
v
Out[52]:
In [53]:
plot(x,dot(A, v),"r")
scatter(x,y)
Out[53]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: