Skip to content

Instantly share code, notes, and snippets.

@weidagang
Last active May 2, 2016 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weidagang/de85735b90258e7e27c91c9039a7463b to your computer and use it in GitHub Desktop.
Save weidagang/de85735b90258e7e27c91c9039a7463b to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
import numpy as np
import matplotlib.pyplot as plt
m = 4
input = np.array([
[1, 6],
[2, 5],
[3, 7],
[4, 10]
])
X = np.matrix([np.ones(m), input[:,0]]).T
y = np.matrix(input[:,1]).T
betaHat = (X.T * X).I * X.T * y
print(betaHat)
plt.figure(1)
xx = np.linspace(0, 5, 2)
yy = np.array(betaHat[0] + betaHat[1] * xx)
plt.plot(xx, yy.T, color='b')
plt.scatter(input[:,0], input[:,1], color='r')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment