Implementation of the k-nearest-neighbour algorithm. More...
Functions | |
def | euclidean_distance |
Calculate the euclidean distance of two n-dimensional points. | |
def | k_nearest_neighbours |
Find for point it's k nearest neighours in the iterable object points |
Implementation of the k-nearest-neighbour algorithm.
Calculate the euclidean distance of two n-dimensional points.
The euclidean distance for two points and is defined as follows:
Definition at line 11 of file k_nearest_neighbour.py.
def face_contour_detector.learing.k_nearest_neighbour.k_nearest_neighbours | ( | point, | |
points, | |||
k, | |||
key = lambda x: x , |
|||
key2 = None , |
|||
distance = euclidean_distance |
|||
) |
Find for point it's k nearest neighours in the iterable object points
point | the reference points which near neighbours you want to find |
points | iterable object of other points (distance to point is calculated for each point in this "set") |
k | defines how many neighbours are found in the result list (if the length of the list is smaller than k a list of points is returned) |
key | the distance function is not called on point and a point in points directly. The key function is called on point and the result is passed to the distance function |
key2 | similar to key but this function is applied to each point in the points "set". Default is None which means that key is used. The advantage of having to key functions is that we can apply different functions on point and all other points. |
distance | a distance function that defines a float distance between two points. The distance function is applied to key(point) and key2(p) where p is a point form points. Default is euclidean_distance |
len(points) < k
the list has length len(points)
. Definition at line 28 of file k_nearest_neighbour.py.