...

/

Test the Network on a Subset

Test the Network on a Subset

Test the network on a MNIST dataset.

Test the network

Now that we’ve trained the network, at least on a small subset of 100 records, we want to test how well that worked. We’ll do this against the second dataset, the training dataset.

First we need to get the test records, and the Python code we’ll use is very similar to what we used to get the training data:

Press + to interact
# load the mnist test data CSV file into a list
test_data_file = open("mnist_test_10.csv", 'r')
test_data_list = test_data_file.readlines()
test_data_file.close()

We unpack this data the same way as before, because it has the same structure:

Press + to interact
# load the mnist test data CSV file into a list
test_data_file = open("mnist_test_10.csv", 'r')
test_data_list = test_data_file.readlines()
test_data_file.close()
#get the first test record
all_values = test_data_list[0].split(',')
#print the label
print(all_values[0])

Before we create a loop to go through all the test records, let’s see what happens if we manually run one test. The following code shows the tenth record from the test dataset being used to query the now-trained neural network:

Press + to interact
image_array = numpy.asfarray(all_values[1:]).reshape((28,28))
matplotlib.pyplot.imshow(image_array, cmap = 'Greys', interpolation = 'None')
matplotlib.pyplot.savefig("output/samplePlot3.png")

We can see that the label for the ...