k-Nearest Neighbors from Scratch by David Lettier

Using JavaScript, we implement the k-Nearest Neighbors algorithm from the bottom up.

Demo and Codebase

If you would like to play with the k-Nearest Neighbors algorithm in your browser, try out the visually interactive demo. All of the code for the demo is hosted on GitHub. Stars are always appreciated.

The Scenario

Say you have a garden that is host to many different kinds of plants. Each plant’s location in the garden is based on two of its features. The west to east direction of the garden corresponds to the diameter of the plant’s flower while the south to north direction relates to the length of the plant’s leaf. Each plant in the garden has been carefully labeled with a small tag stuck in the dirt located near its base.

Source: k-Nearest Neighbors from Scratch by David Lettier

 

Raony Guimaraes