Evaluate the Performance of the Neural Network
Train and test the neural network with a full dataset and evaluate its performance.
We'll cover the following...
Training and testing with a full dataset
Previously, we added a simple code to work out the fraction of correct answers. Let’s see what this updated code produces:
Press + to interact
# test the neural network# scorecard for how well the network performs, initially emptyscorecard = []# go through all the records in the test data setfor record in test_data_list:# split the record by the ',' commasall_values = record.split(',')# correct answer is first valuecorrect_label = int(all_values[0])print(correct_label, "correct label")# scale and shift the inputsinputs = (numpy.asfarray(all_values[1:]) / 255.0 * 0.99) + 0.01# query the networkoutputs = n.query(inputs)# the index of the highest value corresponds to the labellabel = numpy.argmax(outputs)print(label, "network's answer")# append correct or incorrect to listif (label == correct_label):# network's answer matches correct answer, add 1 to scorecardscorecard.append(1)else:# network's answer doesn't match correct answer, add 0 to scorecardscorecard.append(0)passpassprint(scorecard)# calculate the performance score, the fraction of correct answersscorecard_array = numpy.asarray(scorecard)print ("performance = ", scorecard_array.sum() / scorecard_array.size)print ("performance percentage = ", (scorecard_array.sum() / scorecard_array.size)*100,"%")
If we get a performance score of 0.7
, that means we achieved 70% accuracy.
Press + to interact
Discussion of the results
Let’s add all this new code we’ve just developed to test the neural network’s performance to our main program.
While we’re at it, let’s change the file names so that we are now pointing to the full training data set of 60,000 records, ...