Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- def normEqn(X, y):
- theta = np.zeros((X.shape[1], 1))
- theta = np.linalg.inv(X.T.dot(X)).dot(X.T).dot(y)
- return theta
- def getPred():
- arr = np.loadtxt("buildings.csv",
- delimiter=",", dtype=int)
- buildingsParams = arr[:, [0, 1]] # 1239,3,229900
- prices = arr[:, [2]]
- ones = np.ones((prices.size, 1), dtype=int, order='C')
- buildingsParams = np.hstack((ones, buildingsParams))
- theta = normEqn(buildingsParams, prices)
- return theta
- def main():
- theta = getPred()
- #predict
- area = int(input("area: "))
- rooms = int(input("rooms: "))
- X=np.array([1, area, rooms])
- price = X.dot(theta)
- print(f"price: {int(price[0])}$")
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement