Solution :
According to the question, the following datasheet contains eight items representing the colored points o the x-y plane.
We have to use this data as training set to run the k-nearest classification algorithm to decide most likely color for a new item with x = 3 and y = 3.
The distance between the points is actual distance on x-y plane, called as Eucledian distance.
We will make a data table, by calculating distance from (3, 3) of each point. By using formula :
Distance,
x y Color Distance from point (3, 3)
1 1 Red
1 3 Green
2 5 Blue
3 5 Green
4 1 Blue
4 4 Red
5 3 Blue
5 4 Green
Now, we will do sorting of colors with distance in ascending order.
We get, [ Red, Green, Green, Blue, Blue, Blue, Green, Red]
Now if we run the algorithm with k = 1, then we pick only 1 color having the shortest distance that will be assigned to the given point.
Therefore the color is RED.
If we run the algorithm with k = 4, we will pick up
with shortest distance which are
. Since, now we know, Green has the greatest frequency among 4, hence the answer is Green.