Documentation

Nearest Neighbors

k nearest neighbors classification using Kd-tree search

To train a k-nearest neighbors model, use the Classification Learner app. For greater flexibility, train a k-nearest neighbors model using fitcknn in the command-line interface. After training, predict labels or estimate posterior probabilities by passing the model and predictor data to predict.

Apps

Classification Learner Train models to classify data using supervised machine learning

Functions

fitcknn Fit k-nearest neighbor classifier
predict Predict k-nearest neighbor classification
templateKNN k-nearest neighbor classifier template
loss Loss of k-nearest neighbor classifier
crossval Cross-validated k-nearest neighbor classifier
compareHoldout Compare accuracies of two models using new data
pdist Pairwise distance between pairs of objects
pdist2 Pairwise distance between two sets of observations
ExhaustiveSearcher Prepare exhaustive nearest neighbors searcher
KDTreeSearcher Grow Kd-tree
createns Create object to use in k-nearest neighbors search

Classes

ClassificationKNN k-nearest neighbor classification
ClassificationPartitionedModel Cross-validated classification model

Was this topic helpful?