KNN can be run in these steps:1.
Store the output values of the nearest neighbors to query scenario in vectorby repeating the following loop times:a.
Go to the next scenario in the data set, where is the current iteration within thedomainb.
If is not set or :c.
Loop until we reach the end of the data set (i.e. )d.
Store into vector and into vector2.
Calculate the arithmetic mean output across as follows:3.
Return as the output value for the query scenario
This paper was accompanied by ademonstration application written inVisual Basic that visualizes theworkings of the KNN algorithm.The examples below can becomputed using the respectiveevaluation buttons, or a customquery can be assembled. The threenearest neighbors are highlighted inthe table and the results of evaluations appear on the right-hand pane.
In our PlayTennis data set, we can calculate the KNN to the following query situation:We will use Absolute, unscaled distances to investigate the three nearest neighbors to : sothat . Running the algorithm as described in the previous chapter should result in thefollowing vector and accompanying output vector :