Python Forum
KNN algorithm Assignment can't understand the question
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
KNN algorithm Assignment can't understand the question
#1
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.
Reply


Messages In This Thread
KNN algorithm Assignment can't understand the question - by spoooder - May-24-2020, 03:09 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Question code from datacamp I don't understand fad3r 3 3,930 Feb-04-2018, 08:44 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020