1
$\begingroup$

After I calculated the similarities matrix, how do I get the neighbors? For example, consider the matrix of similarities between users, if I did not make any mistakes, the matrix must be symmetric with diagonal 1 considering pearson.

u0: 1.0  -0.2  0.8  -0.6  0.2
u1:-0.2   1.0  0.7  -0.3  0.4
u2: 0.8   0.7  1.0   0.4  0.3
u3:-0.6  -0.3  0.4   1.0  0.8
u4: 0.2  -0.4  0.3   0.8  1.0

So if I want get 2 neighbors for u0, the result would be [u2: .08, u4:0.2].

I didn't undertando why to do KNN and not a sort operation on its row?

$\endgroup$
  • 1
    $\begingroup$ If you only need neighbors for one observation, any home brewed search procedure will do in time. kNN search algorithms can just be very efficient and will likely involve some kind of partial sorting, see en.wikipedia.org/wiki/Nearest_neighbor_search $\endgroup$ – Soren Havelund Welling Jul 25 '16 at 14:11
  • $\begingroup$ But in this case the will knn be only with 1 dimension point? $\endgroup$ – Alex Jul 25 '16 at 14:23
  • 1
    $\begingroup$ Yes, your similarity distances are one dimensional. The space from which they were created are not necessarily one dimensional. Your right it is not difficult to find the nearest neighbors for one observation, once you already have the similarity matrix. E.g. R kknn package will both compute the distance matrix (by some metric and smoothing kernel), and identify the k nearest neighbors for all train observations and for a test set pretty fast. So its all about CPU time and memory consumption. For a small data set, any search implementation will suffice. $\endgroup$ – Soren Havelund Welling Jul 25 '16 at 16:20

Your Answer

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

Browse other questions tagged or ask your own question.