-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageClassifier_project.py
129 lines (60 loc) · 1.26 KB
/
ImageClassifier_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
#!/usr/bin/env python
# coding: utf-8
# In[2]:
import pandas as pd
import numpy as np
from matplotlib import pyplot as ply
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
get_ipython().run_line_magic('matplotlib', 'inline')
# In[6]:
data=pd.read_csv('emnist.csv')
data.head()
# In[24]:
#extracting the data
d=data.iloc[2,1:].values
# In[32]:
#reshaping the extracted data
d=d.reshape(28,28).astype('uint8')
ply.imshow(d)
# In[34]:
#separating label and pixels
df_x=data.iloc[:,1:]
df_y=data.iloc[:,0]
# In[36]:
#train and test the datas
x_train,x_test,y_train,y_test=train_test_split(df_x,df_y,test_size=0.2,random_state=4)
# In[38]:
#check data
x_train.head()
# In[40]:
y_train.head()
# In[42]:
#calling rf classifier
rf=RandomForestClassifier(n_estimators=100)
# In[45]:
#fit the model
rf.fit(x_train,y_train)
# In[47]:
#prediction test
pred=rf.predict(x_test)
# In[49]:
pred
# In[51]:
#check prediction accuracy
s=y_test.values
#calculate no of correct predictions
count=0
for i in range(len(pred)):
if pred[i]==s[i]:
count=count+1
# In[53]:
w=count
# In[55]:
#total values which was predicted
len(pred)
# In[59]:
len(pred)
# In[4]:
#accuracy
2785/3760