Advertisement
STANAANDREY

recomand prices

Jul 25th, 2023 (edited)
840
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. import numpy as np
  2.  
  3. def normEqn(X, y):
  4.     theta = np.zeros((X.shape[1], 1))
  5.     theta = np.linalg.inv(X.T.dot(X)).dot(X.T).dot(y)
  6.     return theta
  7.  
  8. def getPred():
  9.     arr = np.loadtxt("buildings.csv",
  10.                      delimiter=",", dtype=int)
  11.     buildingsParams = arr[:, [0, 1]]  # 1239,3,229900
  12.     prices = arr[:, [2]]
  13.  
  14.     ones = np.ones((prices.size, 1), dtype=int, order='C')
  15.     buildingsParams = np.hstack((ones, buildingsParams))
  16.     theta = normEqn(buildingsParams, prices)
  17.     return theta
  18.  
  19. def main():
  20.  
  21.     theta = getPred()
  22.     #predict
  23.     area = int(input("area: "))
  24.     rooms = int(input("rooms: "))
  25.     X=np.array([1, area, rooms])
  26.     price = X.dot(theta)
  27.     print(f"price: {int(price[0])}$")
  28.  
  29. if __name__ == '__main__':
  30.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement