K-Nearest Neighbors

K-Nearest Neighbors (KNN) is a method belonging to a category called instance-based learning. In this case, there's no parametrized model, but rather a rearrangement of the samples in order to speed up specific queries. In the simplest case (also known as brute-force search), let's say we have a dataset X containing M samples xi ∈ ℜN. Given a distance function d(xi, xj), it's possible to define the radius neighborhood of a test sample xi as:

The set ν(xi) is a ball centered on xi and including all the samples whose distance is less or equal to R. Alternatively, it's possible to compute only the top k nearest neighbors, ...

Get Hands-On Unsupervised Learning with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.