KNN Interactive demo in your browser

Today, I want to show you a new interactive demo of the KNN (K-Nearest Neighbors) algorithm that I have added to my website. It is designed to be used for teaching purpose to illustrate how the K-Nearest Neighbors algorithm works.

You can try the KNN Interactive demo here. The interface is like this:

In the section 1 of the webpage, you can enter some data that is a list of records or instances to be used by KNN to make predictions. The first line is the list of attributes. Then, each following line is a record, wich is a list of values separated by single spaces. The values can be categorical or numerical.

Then, the value of K can be selected in section 2 of the webpage. For the purpose of teaching, values of K are restricted to be between 1 to 100.

Then, you can provide an instance to classify in section 3 of the webpage. The instance to classify is a list of attribute values but one of them must be replaced by ? meaning that we want to predict this attribute value using KNN.

Finally, by clicking Run KNN button, the result are displayed like this:

It indicates the K most similar instances, the calculated distances between those instances and the instance, and the predicted attribute value.

It is possible to run the demo with different values of K and different data to observe the result, which can be good for learning.


This tool is for teaching purpose. If you want to try a more efficient implementation in Java, you could try the one from the SPMF data mining software, which is free and open source.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *