Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

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 labels using k-nearest neighbor classification model
templateKNN k-nearest neighbor classifier template
ExhaustiveSearcher Prepare exhaustive nearest neighbors searcher
KDTreeSearcher Grow Kd-tree
createns Create object to use in k-nearest neighbors search

Using Objects

ClassificationKNN k-nearest neighbor classification
ClassificationPartitionedModel Cross-validated classification model
ExhaustiveSearcher Exhaustive nearest neighbors searcher
KDTreeSearcher Nearest neighbor search using Kd-tree

Examples and How To

Train Nearest Neighbor Classifiers Using Classification Learner App

Learn how to train nearest neighbor classifiers.

Steps in Supervised Learning

While there are many Statistics and Machine Learning Toolbox™ algorithms for supervised learning, most use the same basic workflow for obtaining a predictor model.

k-Nearest Neighbor Search and Radius Search

Given a set X of n points and a distance function, k-nearest neighbor (kNN) search lets you find the k closest points in X to a query point or set of points Y. For a positive real value r, radius search finds all points in X that are within a distance r of each point in Y.

Construct KNN Classifier

Construct a k-nearest neighbor classifier for the Fisher iris data.

Examine Quality of KNN Classifier

Examine the quality of a k-nearest neighbor classifier using resubstitution and cross-validation.

Predict Classification Using KNN Classifier

Predict classification for a k-nearest neighbor classifier.

Modify KNN Classifier

Modify a k-nearest neighbor classifier.

Concepts

Characteristics of Classification Algorithms

Classification algorithms vary in speed, memory usage, interpretability, and flexibility.

Pairwise Distance Metrics

Categorizing query points based on their distance to points in a training data set can be a simple yet effective way of classifying new points.

k-Nearest Neighbor Search and Radius Search

Given a set X of n points and a distance function, k-nearest neighbor (kNN) search lets you find the k closest points in X to a query point or set of points Y. For a positive real value r, radius search finds all points in X that are within a distance r of each point in Y.

K-Nearest Neighbor Classification for Supervised Learning

The ClassificationKNN classification model lets you:

Was this topic helpful?