Handwritten digits classifier using a fully-connected neural network implemented in JavaScript and trained using the MNIST database of handwritten digits.
git clone https://github.com/Firlej/MNIST-image-classifier
cd MNIST-image-classifier
gunzip data_train.js.gz data_test.js.gz data_min.js.gz
It's all written in pure JavaScript without any libraries except the one I developed myself oskar.js. The library constains a Matrix
class, which has all the essential methods, a neural network needs. On top of that I built Layer
class which in turn is used by the NeuralNetwork
class that wraps all the structures.
I've implemented the neural network so you specify any number of hidden layers, with any number of neurons in each layer.
let nn = new NeuralNetwork(784, [40, 40], 10);
There are three parameters. The number of input neurons, an array of numbers which represent the number of neurons for each hidden layer, and the number of output neurons.
Visualisation of the net learning. Weights are being constantly improved and the network's accuracy reaches ~96% after training.
Weights of a single neuron in the first hidden layer
This gif visualises the weights between the input layer and one of the neurons in the first hidden layer.