May-24-2020, 03:09 AM

The below is the question, I have no knowledge regarding KNN , been following some tutorials but can't get the jest of the question. Someone please explain it to me. Thnaks

1. Load the data.

2. Initialize K to your chosen number of neighbors.

3. For each example in the data (read from file):

3.1 Calculate the distance between the query(user input) example and the current example from

the data.

3.2 Add the distance and the index of the example to an ordered collection (your chosen data

structure).

4. Sort the ordered collection of distances and indices from smallest to largest (in ascending order) by the

distances.

5. Pick the first K entries from the sorted collection.

6. Get the labels of the selected K entries.

7. Depending on the labels you obtained, classify your new point.

a. Based on this algorithm, write a Python function myknn that takes as inputs: 1. the value of K

(no. of neighbors) and, 2. one data(example) to be classified, and performs k-NN based

classification of that input point based on some old data which is read from the given file

(Entrance_Selection.csv). The function should return the output class of the given input example.

Make sure your function gives an exception if there is any problem when reading the file. Hint: Use

exception handling.

Note: The default value of k should be 5.

1. Load the data.

2. Initialize K to your chosen number of neighbors.

3. For each example in the data (read from file):

3.1 Calculate the distance between the query(user input) example and the current example from

the data.

3.2 Add the distance and the index of the example to an ordered collection (your chosen data

structure).

4. Sort the ordered collection of distances and indices from smallest to largest (in ascending order) by the

distances.

5. Pick the first K entries from the sorted collection.

6. Get the labels of the selected K entries.

7. Depending on the labels you obtained, classify your new point.

a. Based on this algorithm, write a Python function myknn that takes as inputs: 1. the value of K

(no. of neighbors) and, 2. one data(example) to be classified, and performs k-NN based

classification of that input point based on some old data which is read from the given file

(Entrance_Selection.csv). The function should return the output class of the given input example.

Make sure your function gives an exception if there is any problem when reading the file. Hint: Use

exception handling.

Note: The default value of k should be 5.