Last active
May 2, 2016 05:19
-
-
Save weidagang/de85735b90258e7e27c91c9039a7463b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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