Skip to content

Instantly share code, notes, and snippets.

@kino6052
Created March 21, 2021 19:27
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 kino6052/3b8468bb0246889151d5cbb7940b4252 to your computer and use it in GitHub Desktop.
Save kino6052/3b8468bb0246889151d5cbb7940b4252 to your computer and use it in GitHub Desktop.
x = np.array([[1, 1],[1, 2],[1, 3]]) ## must contain first column with one for theta bias
y = np.array([[4.5], [5.5], [8.5]])
_x = np.dot(x.T, x)
xI = np.linalg.inv(_x)
n = np.dot(xI,x.T)
theta = np.dot(n, y)
print(theta)
print(theta[0], theta[0][0])
print(x[0], x[0][0])
y1_hat = theta[0][0] + theta[1][0]*x[0][1]
print(y1_hat)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment