A while ago, I became intrigued by the basic way in which machine learning works. More specifically, I wanted to understand the low level calculations and algorithms used to train a neural network in a basic capacity. I therefore chose to implement one from scratch in JavaScript.

Without any machine learning libraries, I realised that I couldn’t feasibly do anything very complicated or impressive. Instead, my goal was to train a network to classify an RGB representation of a colour by its name (from a list of 10 standard colours).

Below is the result of a fair amount of experimentation and research. It is far from perfect. It could be improved in many ways and applies very few proper machine learning techniques, other than the basics of a neural network.

It is initialised with random values, meaning that its initial guesses are likely to be completely wrong. The network can be trained by clicking the train button or checking the ‘loop’ box to train repeatedly. The number of training iterations (known colours) that are used each time is set by the numeric input. When ‘loop’ is not checked, the 3 sliders can be used to input an RGB colour manually, and the network will guess the name of it. Note: this is purely to see what the network has learnt and cannot be used to train it.


Loop

Framerate: -

Training count: -