CSV to K Nearest Neighbor (KNN) Classifier


See the video here.



The K-Nearest Neighbor code in Tensorflowjs is fairly easy. It is just calculating the distance between two points on a graph. In 2D it would just be the distance formula, kind of like the pythagoras equation for the hypotenus of a right triangle c = square root of (a squared + b squared).

Lets try a 3, 4, 5 triangle: If the graph starts at location 0,0 and go 3 along the x axis and 4 up, what is the unknown distance from the origin to this 3, 4 location

Look at how bareable the code is:



...











Same thing as above but stringing the operations together in one line which is strangely easier to read



...











Now try a KNN with real 2 D or more dimensional data. The Machine Learning part is the same as the above example, however lots of regular Javascript is needed to parse and organise the data before and after running the very small Machine Learning KNN classifier. Find other text datasets at https://archive.ics.uci.edu/ml/datasets.html?sort=nameUp&view=list
or at https://en.m.wikipedia.org/wiki/List_of_datasets_for_machine_learning_research




Original CSV:




Headings:
Data:Labels
The K value:
The unknown:





...











This Github, ... this Github Website Version, ... this Hosted Website Version, ... Tensorflowjs

By Jeremy Ellis
Twitter@rocksetta
Website http://rocksetta.com
Use at your own risk!