0
$\begingroup$

I am getting attr(, "nn.index") as part of my KNN output in R. What is meant by that and how is this value getting calculated?

knn.pred <- knn(tdm.stack.nl_train, tdm.stack.nl_Test, tdm.cand_train)
print(knn.pred)

> knn.pred


[1] Silent      Silent      Silent      Silent      Silent      Silent      Silent     
 [8] Silent      Silent      Silent    


attr(,"nn.index")


      [,1]
[1,]  292  
[2,]  292  
[3,]  343  
[4,]  444  
[5,]  250  
[6,]  445  
[7,]  270  
[8,]  228  
[9,]  302  
[10,]  355  
$\endgroup$
1
$\begingroup$

I guess you are using the fnn package.

attr is a list of attributes which can be used for both nn.index and nn.dist. In this case, you are using index.

So, index returns an n x k matrix for the nearest neighbor indice.

And the definition of the nearest neighbor index is:

The nearest neighbor index is expressed as the ratio of the observed distance divided by the expected distance.

Definition reference

$\endgroup$
  • $\begingroup$ Thanks for the reply. Is there anyway to know what their actual value of observed distance and expected distances are? I am using KNN algorithm for a classification problem in text mining project and i want to know find the keywords influencing the classification. It wil be helpful if you can let me know how to retrive the absolute values of these distances. Thank you. $\endgroup$ – Arun Sep 24 '15 at 8:53
  • $\begingroup$ For that, you use nn.dist instead of nn.index . However, the documentation of the fnn package would help you understand better (cran.r-project.org/web/packages/FNN/FNN.pdf) $\endgroup$ – Dawny33 Sep 24 '15 at 8:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.