-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlinear reg
More file actions
48 lines (44 loc) · 1.23 KB
/
linear reg
File metadata and controls
48 lines (44 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn import linear_model
---------------------------------
df=pd.read_csv("D:\\homeprices.csv")
df
--------------------------------
%matplotlib inline
plt.xlabel('area')
plt.ylabel('price')
plt.scatter(df.area,df.price,color='red',marker='+')
----------------------------------------------------------
reg=linear_model.LinearRegression()
-----------------------------------------------
reg.fit(df[['area']],df.price)
------------------------------------
reg.predict([[3300]])
-----------------------------
reg.coef_
---------------------------------
reg.intercept_
-------------------------
3300*135.78767123+180616.43835616432
------------------------------------
reg.predict([[5000]])
---------------------------
d=pd.read_csv("D:\\fp\\areas.csv")
d
------------------------------------------
d.head(3)
------------------
reg.predict(d)
----------------
d['prices']=p
--------------------
d.to_csv("prediction.csv")
----------------------------
%matplotlib inline
plt.xlabel('area')
plt.ylabel('price')
plt.scatter(df.area,df.price,color='red',marker='+')
plt.plot(df.area,reg.predict(df[['area']]),color='blue')
----------------------------------------------------------