First MNIST model

Using the neural network class from Part I, I train a neural network on the MNIST dataset.

data_train, data_valid, data_test = mnist_loader.load_data()

def train():
    net = neural1.Network([784, 30, 10])
    print(f"Accuracy on testing data: {net.accuracy(data_test)}")
    net.sgd(data_train, 10, 10, 3.0)
    print(f"Accuracy on testing data: {net.accuracy(data_test)}")

    with open('network1.config', 'wb') as f:
        pickle.dump(net, f)

The results of running this were:

Accuracy on testing data: 0.08475
Epoch 0 starting.   Epoch 0 done. Accuracy is 0.902
Epoch 1 starting.   Epoch 1 done. Accuracy is 0.912
Epoch 2 starting.   Epoch 2 done. Accuracy is 0.931
Epoch 3 starting.   Epoch 3 done. Accuracy is 0.939
Epoch 4 starting.   Epoch 4 done. Accuracy is 0.930
Epoch 5 starting.   Epoch 5 done. Accuracy is 0.943
Epoch 6 starting.   Epoch 6 done. Accuracy is 0.943
Epoch 7 starting.   Epoch 7 done. Accuracy is 0.948
Epoch 8 starting.   Epoch 8 done. Accuracy is 0.948
Epoch 9 starting.   Epoch 9 done. Accuracy is 0.950
Accuracy on testing data: 0.9496333333333333

Next steps

I will continue to work through Nielsen’s online book, learning more about neural networks.