Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- from numpy.linalg import inv
- import matplotlib.pyplot as plt
- def get_best_param(X, y):
- X_transpose = X.T
- best_params = inv(X_transpose.dot(X)).dot(X_transpose).dot(y)
- # normal equation
- # theta_best = (X.T * X)^(-1) * X.T * y
- return best_params # returns a list
- def generate_data():
- X = 2 * np.random.rand(100, 1)
- y = 4 + 3 * X + np.random.randn(100, 1)
- # y = 4 + 3X + Gaussian noise
- # theta_0 or Bias Term = 4
- # theta_1 = 3
- return X, y
- def main():
- X, y = generate_data()
- plt.plot(X, y, "r.")
- plt.ylabel('price (x1000)')
- plt.xlabel('size(m^2)')
- plt.show()
- # main
- if __name__ == "__main__":
- main()
- print(2 * np.random.rand(3, 3))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement