In [11]:
%matplotlib inline
import numpy
import seaborn as sns

n=100
shoesize=numpy.random.randn(n,1)*5 + 40
#sns.distplot(shoesize)

In [14]:
speed = 100 + shoesize*0.75 + numpy.random.randn(n,1)*10
#sns.distplot(speed)
print numpy.corrcoef(shoesize.T,speed.T)


[[ 1.          0.40913353]
 [ 0.40913353  1.        ]]

In [16]:
Y=speed
X=numpy.hstack((shoesize,numpy.ones((n,1))))
print X.shape
print Y.shape


(100, 2)
(100, 1)

In [18]:
B_hat = numpy.linalg.inv(X.T.dot(X)).dot(X.T).dot(Y)
print B_hat


[[   0.75987924]
 [ 100.63682636]]

In [22]:
import matplotlib.pyplot as plt
plt.scatter(shoesize,speed)
Y_hat = X.dot(B_hat)
plt.plot(X[:,0],Y_hat,color='red')


Out[22]:
[<matplotlib.lines.Line2D at 0x7f13c4f93c10>]

In [ ]:


In [ ]:


In [ ]:


In [ ]: