Advertisement
brandblox

Lab_ML(20/01/25)

Jan 20th, 2025
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. import pandas as pd
  2. import matplotlib.pyplot as plt
  3. import numpy as np
  4. from sklearn import linear_model
  5.  
  6. header = ["Area", "Price"]
  7. data=[[2600,550000],[3000,565000],[3200,610000],[3600,680000],[4000,725000]]
  8. data = pd.DataFrame(data, columns=header)
  9. data.to_csv('D://ARIJIT-6SEM/ML/House_price.csv',index=False )
  10.  
  11. Display_csv = pd.read_csv('D://ARIJIT-6SEM/ML/House_price.csv', usecols= ['Area','Price'])
  12. Display_csv
  13.  
  14. plt.scatter(Display_csv['Area'],Display_csv['Price'],c='Blue',marker='*')
  15. plt.xlabel("Area in sq. ft.")
  16. plt.ylabel("Price in US$")
  17. plt.show()
  18.  
  19. reg=linear_model.LinearRegression()
  20. reg
  21.  
  22. Display_csv['Area']
  23. Display_csv['Price']
  24. reg.fit(Display_csv[['Area']], Display_csv.Price)
  25.  
  26. p=reg.predict([[6000]])
  27. p
  28.  
  29. q = reg.coef_
  30. q
  31.  
  32. r = reg.intercept_
  33. r
  34.  
  35. y =q*6000 +r
  36. y
  37.  
  38. plt.xlabel("Area in sq. ft.")
  39. plt.ylabel("Price in US$")
  40. plt.scatter(Display_csv['Area'],Display_csv['Price'],c='Blue',marker='*')
  41. plt.plot(Display_csv['Area'], reg.predict(Display_csv[['Area']].values))
  42. plt.show()
  43.  
  44. x=np.array(Display_csv['Area'])
  45. y=np.array(Display_csv['Price'])
  46. meanofx=sum(x)/len(x)
  47. meanofy=sum(y)/len(y)
  48. m1=0
  49. m2=0
  50. for i in range(len(x)):
  51.     m1=m1+(x[i]-meanofx)*(y[i]-meanofy)
  52.     m2=m2+(x[i]-meanofx)**2
  53. b1=m1/m2
  54. b0=meanofy-b1*meanofx
  55. y=b0+b1*6000
  56. y
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement