A Nearest neighbor search locates the k-nearest neighbors or all neighbors within a specified distance to query data points, based on the specified distance metric. Available distance metrics include Euclidean, Hamming, and Mahalanobis, among others.
Statistics and Machine Learning Toolbox™ offers two ways to find nearest neighbors. You can create a
searcher object with a training data set, and pass the object and query data
sets to the object functions (
rangesearch). Or, you can use the
rangesearch functions, which take
both a training data set and a query data set directly. Creating a searcher
object is preferable when you have multiple query data sets because the searcher
object stores information common to the data sets. For example, a
KDTreeSearcher object stores a
Categorize data points based on their distance to points in a training data set, using a variety of distance metrics.