Find knn (nearest neighbour) point give a data set
Ältere Kommentare anzeigen
Hello, I have this simple data set:
Class1 = [1 0; 0.5 1; 0.5 1.5];
How do I go about finding the "nearest neighbor" point of that data set using the euclidean distance?
That is, generate a point based on the knn algorithm that will be closest to the three points.

The point highlighted in orange should be where the calculated "nearest neighbor" point should be?
5 Kommentare
Walter Roberson
am 16 Okt. 2016
Is the question:
- Generate a new point (typically not already present in the dataset) such that the sum of the Euclidean distances to the three given points will be smallest?
- Generate a new point (typically not already present in the dataset) such that the sum of the squares of the Euclidean distances to the three points will be smallest?
- Generate a new point (typically not already present in the dataset) such that the new point would be one of the k closest neighbors of each of the three points and such that the sum of the Euclidean distances to the three given points will be smallest?
- Generate a new point (typically not already present in the dataset) such that the new point would be one of the k closest neighbors of each of the three points and such that the sum of the squares of the Euclidean distances to the three points will be smallest?
- Find an existing point already in the dataset such that the sum of the Euclidean distances to the three given points will be smallest?
- Find an existing point already in the dataset such that the sum of the squares of the Euclidean distances to the three given points will be smallest?
- Find an existing point already in the dataset such that point is one of the k closest neighbors for each of the three given points, and such that the sum of the Euclidean distances to the three given points will be smallest?
- Find an existing point already in the dataset such that point is one of the k closest neighbors for each of the three given points, and such that the sum of the squares of the Euclidean distances to the three given points will be smallest?
monkey_matlab
am 16 Okt. 2016
Star Strider
am 17 Okt. 2016
The definition of the method in 4. is the centroid, calculated simply as the mean. (It can easily be shown that the mean is the least-squares estimator desired.)
Walter Roberson
am 17 Okt. 2016
Not quite. For option 2 the answer would be the centroid, but the centroid would not necessarily become one of the nearest k neighbors of each of the three points.
It is necessary to first find the k nearest neighbors of the three points, and find the euclidean distance from the last of those k points in each case. That gives you a radius around each point; if the generated new point is further away than the radius then it would not become one of the k nearest neighbors relative to that point. The generated point must now be some point that is within the area of intersection of the three radii relative to their respective points. This will not be possible in the general case; it would not even be generally possible if there were only 2 points.
Consider that for any given point, up to (all but 2) could be close by to them, so your k could end up having to be high in order for the furthest away from the first point to be a radius large enough to include the ranges from the second and third points.
monkey_matlab
am 17 Okt. 2016
Bearbeitet: Walter Roberson
am 17 Okt. 2016
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Nearest Neighbors finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!