K-Nearest Neighbours is one of the most basic yet essential classification algorithms in Machine Learning. It belongs to the supervised learning domain and finds intense application in pattern recognition, data mining and intrusion detection.

```
For Example:
Consider the following table of data points containing two
features/groups "Red and Green":
Given another set of data points (testing data), allocate
these points a feature/group by analyzing the training set.
White Point represents an unclassified point
```**Intuition**
If we plot these points on a graph, we may be able to locate
some clusters, or groups. Now, given an unclassified point,
we can assign it to a group by observing what group its
nearest neighbours belong to. This means, a point close to a
cluster of points classified as ‘Red’ has a higher probability
of getting classified as ‘Red’.Intuitively, we can see that the
first point (2.5, 7) should be classified as ‘Green’ and the
second point (5.5, 4.5) should be classified as ‘Red’.

Your are required to complete the function **classifyAPoint()**, which should return that to which feature/group will be the test data belong.

**Input:**

The function takes four arguments as input, an array of structure **(arr[])** whose each element represents the coordinates and the type of the feature/group to which the point belong, an integer **N **denoting the total number of points, an integer **K **denoting the number of neighbours to consider and an test data (test) whom which needed to be classified.

There will be **T** test cases and for each test case the function will be called separately.

**Output:**

For each test case function should return the group to which the test data would belong.

**Constraints:**

1<=T<=100

1<=N<=100

-100.00<=X,Y<=100

**Example:
Input:**

5

1 2 1 1 3 1 2 3 0 0 1 0 0 0 0

1 1 3

5

1 2 0 1 3 1 2 3 0 0 1 1 0 0 1

1 1 4

0

1

**Note:**The **Input/Ouput** format and **Example** given are used for system's internal purpose, and should be used by a user for **Expected Output** only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code.

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

VISHESHA SADU | 27 |

ghanshyam648 | 25 |

Biswajit3 | 21 |

karthik_kasaragadda | 20 |

tanya_sharma | 18 |

KshatriyaYash | 1066 |

nikhil_sojan | 978 |

lonecoder | 935 |

mazumderrohit8 | 864 |

SumitSingh27 | 832 |

blackshadows | 5327 |

Ibrahim Nash | 5215 |

akhayrutdinov | 5111 |

mb1973 | 4468 |

Quandray | 4444 |

Login to report an issue on this page.