In [40]:
%pylab inline


Populating the interactive namespace from numpy and matplotlib

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]:
<matplotlib.collections.PathCollection at 0x93d8518>

In [46]:
A = hstack([x, ones_like(x)])

In [47]:
v = linalg.lstsq(A, y)[0]
v


Out[47]:
array([[ 4.90957816],
       [-1.08990893]])

In [48]:
plot(x,dot(A, v),"r")
scatter(x,y)


Out[48]:
<matplotlib.collections.PathCollection at 0x955dd68>

In [49]:
y =3*x**2+15*x+2+error

In [50]:
scatter(x,y)


Out[50]:
<matplotlib.collections.PathCollection at 0x97a3da0>

In [51]:
A = hstack([x**2,x, ones_like(x)])

In [52]:
v = linalg.lstsq(A, y)[0]
v


Out[52]:
array([[  2.91833232],
       [ 17.27794096],
       [-12.14226866]])

In [53]:
plot(x,dot(A, v),"r")
scatter(x,y)


Out[53]:
<matplotlib.collections.PathCollection at 0x98d70f0>

In [ ]:


In [ ]:


In [ ]:


In [ ]: