Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import matplotlib.pyplot as plt
- import numpy as np
- from sklearn import linear_model
- header = ["Area", "Price"]
- data=[[2600,550000],[3000,565000],[3200,610000],[3600,680000],[4000,725000]]
- data = pd.DataFrame(data, columns=header)
- data.to_csv('D://ARIJIT-6SEM/ML/House_price.csv',index=False )
- Display_csv = pd.read_csv('D://ARIJIT-6SEM/ML/House_price.csv', usecols= ['Area','Price'])
- Display_csv
- plt.scatter(Display_csv['Area'],Display_csv['Price'],c='Blue',marker='*')
- plt.xlabel("Area in sq. ft.")
- plt.ylabel("Price in US$")
- plt.show()
- reg=linear_model.LinearRegression()
- reg
- Display_csv['Area']
- Display_csv['Price']
- reg.fit(Display_csv[['Area']], Display_csv.Price)
- p=reg.predict([[6000]])
- p
- q = reg.coef_
- q
- r = reg.intercept_
- r
- y =q*6000 +r
- y
- plt.xlabel("Area in sq. ft.")
- plt.ylabel("Price in US$")
- plt.scatter(Display_csv['Area'],Display_csv['Price'],c='Blue',marker='*')
- plt.plot(Display_csv['Area'], reg.predict(Display_csv[['Area']].values))
- plt.show()
- x=np.array(Display_csv['Area'])
- y=np.array(Display_csv['Price'])
- meanofx=sum(x)/len(x)
- meanofy=sum(y)/len(y)
- m1=0
- m2=0
- for i in range(len(x)):
- m1=m1+(x[i]-meanofx)*(y[i]-meanofy)
- m2=m2+(x[i]-meanofx)**2
- b1=m1/m2
- b0=meanofy-b1*meanofx
- y=b0+b1*6000
- y
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement