-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mobile Price Classification classify mobile price range PROJECT.py
214 lines (93 loc) · 2.47 KB
/
Mobile Price Classification classify mobile price range PROJECT.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
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import pandas as pd
import numpy as np
# In[2]:
df_t = pd.read_csv(r'C:\Users\shiva\Desktop\dataset\train.csv')
df_te = pd.read_csv(r'C:\Users\shiva\Desktop\dataset\test.csv')
# In[3]:
df_t
# In[4]:
df_te
# In[5]:
import seaborn as sns
# In[5]:
import matplotlib.pyplot as plt
# In[6]:
matplotlib inline
# In[7]:
df_t.shape
# In[8]:
df_t.describe()
# In[9]:
df_t.info()
# In[10]:
plt.figure(figsize = (12,6))
sns.heatmap(df_t.corr())
plt.show()
# In[11]:
#Plotting Relation between Price Range & Battery Power
plt.figure(figsize = (12,6))
sns.barplot(x = 'price_range' , y = 'battery_power' , data = df_t)
plt.show()
# In[12]:
#Plotting Relation Between Price Range & pixel Height / Width
plt.figure(figsize = (14,6))
plt.subplot(1,2,1)
sns.barplot(x = 'price_range' , y = 'px_height' , data = df_t , palette = 'Oranges')
plt.subplot(1,2,2)
sns.barplot(x = 'price_range' , y = 'px_width' , data = df_t , palette = 'Greens')
plt.show()
# In[13]:
#Plotting Relation between Price Range & RAM
plt.figure(figsize = (12,6))
sns.barplot(x = 'price_range' , y = 'ram' , data = df_t)
plt.show()
# In[14]:
#Plotting Relation Between Price Range & 3G/4G
plt.figure(figsize = (12,6))
sns.countplot(df_t['three_g'] , hue = df_t['price_range'] , palette = 'pink')
plt.show()
# In[15]:
plt.figure(figsize = (12,6))
sns.countplot(df_t['four_g'] , hue = df_t['price_range'] , palette = 'ocean')
plt.show()
# In[16]:
#Plotting Relation between Price Range & Memory
plt.figure(figsize = (12,6))
sns.lineplot(x = 'price_range' , y = 'int_memory' , data = df_t , hue = 'dual_sim')
plt.show()
# In[17]:
#Data Preprocessing
x = df_t.drop(['price_range'] , axis = 1)
y = df_t['price_range']
# In[18]:
from sklearn.model_selection import train_test_split
x_train, x_test, y_train , y_test = train_test_split(x,y ,test_size = 0.3 ,random_state = 0)
# In[19]:
#KNN
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier(n_neighbors = 10)
knn.fit(x_train , y_train)
# In[20]:
knn.score(x_train , y_train)
# In[21]:
predictions = knn.predict(x_test)
# In[22]:
from sklearn.metrics import accuracy_score
accuracy_score(y_test , predictions)
# In[23]:
df_te.head()
# In[24]:
df_te.shape
# In[25]:
df_te = df_te.drop(['id'] , axis = 1)
df_te.shape
# In[26]:
test_pred = knn.predict(df_te)
# In[27]:
df_te['predicted_price'] = test_pred
# In[29]:
df_te.head()
# In[ ]: