-
Notifications
You must be signed in to change notification settings - Fork 0
/
linear model.py
128 lines (50 loc) · 1.17 KB
/
linear model.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env python
# coding: utf-8
# In[140]:
import pandas as pd
import numpy as np
##Pandas is a library for data analysis and manipulation
# In[141]:
df =pd.read_csv(r"C:\Users\88016.DESKTOP-4LE338V\Documents\dataset.csv")
##Location and File name to load the data into pandas
# In[142]:
df
#Datafram are ready
# In[143]:
import math
#import for math model
# In[144]:
median_bedroom=math.floor(df.bedroom.median())
# In[145]:
median_bedroom
##Find the median of all bedroom
# In[146]:
df.bedroom=df.bedroom.fillna(median_bedroom)
##There will no NaN value ,, The value is add into the datafram
# In[147]:
df
#Check the datafram
# In[148]:
from sklearn import linear_model
##For import the Linear_model
# In[149]:
reg=linear_model.LinearRegression()
# In[150]:
y=df['price']
# In[182]:
x=df.drop(['age','price'],axis=1)
x=x.dropna()
# In[183]:
x
# In[184]:
y
# In[185]:
from sklearn.model_selection import train_test_split
# In[186]:
x_train, x_test, y_train, y_test = train_test_split(
x, y, test_size=0.2, random_state=10)
# In[187]:
reg.fit(x_train,y_train)
# In[188]:
reg.predict([[3000,4]])
# In[ ]: