-
Notifications
You must be signed in to change notification settings - Fork 0
/
scorcard.py
45 lines (37 loc) · 1.35 KB
/
scorcard.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
from neural_network import NeuralNetwork
import numpy
# Setting up the value for the neural network
input_nodes = 784
hidden_nodes = 100
output_nodes = 10
learning_rate = 0.3
# Initializing the neural network
neural_network_object = NeuralNetwork(input_nodes, hidden_nodes,
output_nodes, learning_rate)
training_file = open('mnist_train.csv', 'r')
training_list = training_file.readlines()
training_file.close()
for record in training_list:
values = record.split(',')
input_array = (numpy.asfarray(values[1:])/255.0*0.99)+0.01
target = numpy.zeros(output_nodes)+0.01
target[int(values[0])] = 0.99
neural_network_object.train(input_array, target)
test_file = open('mnist_test.csv', 'r')
test_list = test_file.readlines()
test_file.close()
scorecard = []
def scorecard_generation(record):
test_value = record.split(',')
network_lable = neural_network_object.query(
(numpy.asfarray(test_value[1:])/255.0*0.99)+0.01)
print "Given value:", test_value[0]
print "Network Value:", numpy.argmax(network_lable)
if (int(test_value[0]) == numpy.argmax(network_lable)):
return 1
else:
return 0
scorecard = map(lambda record: scorecard_generation(record), test_list)
print scorecard
print len(scorecard)
print "Accuracy is :", (sum(scorecard)/10000.00)