3,239 views
1 1 vote
I am not able to figure out how the calculation of the $m$ nearest points will be in a single dimensional array using kNN.  Can anyone offer a clue or example?
Thank you
0% Accept Rate Accepted 0 answers out of 2 questions

1 Answer

1 1 vote

It could be a single dimensional array (vector) of $m$ nearest points. For example, let's assume the following are the data-points ($X$) and classes ($y$):

X = np.array([[0,1,3], [1,2,4], [2,3,2], [3,4,3]])
y = np.array([0, 0, 1, 1])

and you want to show us the $k=3$ nearest neighbors to the following array:

test = np.array([[1,2,3]])

 You can create a Numpy array for the  as follows:

array([[1, 0, 2]])

And it means the closest neighbors in order are the second element of $X$ ([1,2,4]), then the first element of $X$ ([0,1,3]), and finally the third element of $X$ ([2,3,2]).

Related questions

1 1 vote
3 3 answers
3.7k
3.7k views
kalyanak.p asked Oct 1, 2018
3,713 views
The KNN function in the sklearn library (when coded properly), outputs the points closest to p based on the value of k, and others.The point(s) would include itself when ...
4 4 votes
1 answers 1 answer
7.6k
7.6k views
tofighi asked Jun 26, 2019
7,618 views
Suppose, you have given the following dataset where x and y are the 2 features and color Red or Blue is the target variable.a) A new data point $x=1$ and $y=1$ is given. ...
3 3 votes
2 2 answers
13.3k
13.3k views
Neo asked Sep 27, 2018
13,333 views
I am wondering what happens as K increases in the KNN algorithm. It seems that as K increases the "p" (new point) tends to move closer to the middle of the decision bound...
1 1 vote
1 1 answer
707
707 views
RSH asked Oct 4, 2018
707 views
I have this question as an assignment, I am having challenges in interpreting this question.Q4. Define a function that takes a 1-d numpy array, a parameter k, and a numbe...
3 3 votes
1 1 answer
1.1k
1.1k views
kalyanak.p asked Sep 26, 2018
1,068 views
I have read online articles involving KNN and its emphasis on normalization. I would like to know if all KNN functions in Python need to involve normalization? I do know ...