-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdigit_recognition.py
More file actions
32 lines (26 loc) · 886 Bytes
/
digit_recognition.py
File metadata and controls
32 lines (26 loc) · 886 Bytes
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
import numpy as np
import matplotlib.pyplot as pt
import pandas as pd
from sklearn.tree import DecisionTreeClassifier
data = pd.read_csv("train.csv").as_matrix()
clf = DecisionTreeClassifier()
#training data
xtrain = data[0:21000, 1:]
train_label = data[0:21000, 0]
clf.fit(xtrain,train_label)
#testing data
xtest = data[21000:, 1:]
actual_label = data[21000:, 0]
#========================================================================
# To plot the particular value and print the same.
# d = xtest[9]
# d.shape= (28,28) #plotting the data so that we can see if it matches.
# pt.imshow(d,cmap='gray')
# pt.show()
# print (clf.predict([xtest[9]]))
#========================================================================
p = clf.predict(xtest)
count = 0
for i in range(0,21000):
count +=1 if p[i] == actual_label[i] else 0
print ("Accuracy = {}".format((count/21000)*100))