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)
In [16]:
Y=speed
X=numpy.hstack((shoesize,numpy.ones((n,1))))
print X.shape
print Y.shape
In [18]:
B_hat = numpy.linalg.inv(X.T.dot(X)).dot(X.T).dot(Y)
print B_hat
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]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: