-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHPP
170 lines (79 loc) · 1.96 KB
/
HPP
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/env python
# coding: utf-8
# # House Price Prediction
# ## Importing Libraries
# IMPORTING SOME REQUIRED DEPENDENCIES FOR THE "HOUSE PRICE PREDICTION" MODEL
#
#
# In[3]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.model_selection import train_test_split
from xgboost import XGBRegressor
from sklearn import metrics
# ## Exploring and Observing the Housing Dataset
# OBSERVING THE DATA SET TO GET THE REQUIRED OBSERVATION AND GET A BETTER UNDERSTANDING OVER THE DATSET
# In[4]:
hdf=pd.read_csv('D:\Datasheet\data (2).csv')
# In[5]:
hdf.head()
# In[6]:
hdf.isnull().sum()
# In[7]:
hdf.info()
# In[8]:
Y=hdf['Price']
X=hdf.drop(['Price'],axis=1)
# In[9]:
Y,X
# In[10]:
print(X.shape,Y.shape)
# In[11]:
hdf.describe()
# ## CORRELATION & HEATMAP
# CORRELATION BETWEEN EVERY FEATURE OF DATASET
#
# In[12]:
corr_hdf=hdf.corr()
# ### HEATMAP:
# HEAT OF THE CORRELATION BETWEEN THE FEATURES OF THE DATASET
# In[13]:
plt.figure(figsize=(16,17))
sns.heatmap(corr_hdf,cbar=True,square=True,fmt='1f',annot=True,annot_kws={'size':10},cmap='Blues')
# ### SPLITTING DATA
# SPLITTING THE TRAINING AND TESTING DATA BY 4:1
#
# In[14]:
X_tr,X_t,Y_tr,Y_t=train_test_split(X,Y,test_size=0.2,random_state=2)
# In[15]:
print(X.shape,X_tr.shape,X_t.shape)
# ### TRAINING
# In[16]:
Md=XGBRegressor()
Md.fit(X_tr,Y_tr)
# ### Prediction
# In[17]:
Md_p=Md.predict(X_tr)
# In[18]:
x1=metrics.mean_absolute_error(Y_tr,Md_p)
X2= metrics.r2_score(Y_tr,Md_p)
# In[19]:
print(x1)
print(X2)
# In[21]:
plt.scatter(Y_tr,Md_p)
plt.xlabel("Actual Prices")
plt.ylabel("Predicted Prices")
plt.title('Actual Price / Predicted Price')
plt.show()
# ### Test Data
#
# In[40]:
t_d_prediction=Md.predict(X_t)
# In[42]:
S1= metrics.r2_score(Y_t,t_d_prediction)
S2 = metrics.mean_absolute_error(Y_t,t_d_prediction)
print("R2 Value error : ", S1 )
print("Mean absolute Error : ",S2)