0

I am trying to implement the knnclassify function on my own.

I have two matrices, train (45x644) and test (5x644) and I am trying to implement knn using euclidean to find the class of test data. I have found the the distance between the two and sorted them. I am at a loss to know what to do after this. I need to return the k data points which are close to my test data, is this right? If yes, how do I do that? I do not want to use the matlab function knnclassify().

6
  • Can you show us what you have tried so far?
    – zeeMonkeez
    Feb 22, 2016 at 3:18
  • Use the above duplicate, but you'll have to modify it to accommodate for multiple test points. A simple loop should suffice.
    – rayryeng
    Feb 22, 2016 at 3:24
  • @rayryeng Thank you for your reply. I used dist = pdist2(train, test, 'euclidean') to find the distance. Is that right? I tried reading about ind, but i am not really clear. Can you please explain in short what is really does?
    – Dan
    Feb 22, 2016 at 3:30
  • I tried using that piece of code. I want the value ind_closest. But this value and the value that i get when i do knnclassify(test,train,group) are different. I am confused. Please help
    – Dan
    Feb 22, 2016 at 3:37
  • @zeeMonkeez: I calculated the distance and have a matrix of 5x45 which later I sorted and followed the steps given in the link that rayryeng provided
    – Dan
    Feb 22, 2016 at 4:07

0

Browse other questions tagged or ask your own question.