Main Content

Nearest Neighbors

knearest neighbors classification usingKd-tree search

To train ak-nearest neighbors model, use theClassification Learnerapp. For greater flexibility, train ak-nearest neighbors model usingfitcknnin the command-line interface. After training, predict labels or estimate posterior probabilities by passing the model and predictor data topredict.

Apps

Classification Learner Train models to classify data using supervised machine learning

Functions

expand all

fitcknn Fitk-nearest neighbor classifier
ExhaustiveSearcher Create exhaustive nearest neighbor searcher
KDTreeSearcher CreateKd-tree nearest neighbor searcher
createns Create nearest neighbor searcher object
crossval Cross-validatedk-nearest neighbor classifier
kfoldEdge Classification edge for observations not used for training
kfoldLoss Classification loss for observations not used for training
kfoldfun 交叉验证函数
kfoldMargin Classification margins for observations not used for training
kfoldPredict Predict response for observations not used for training
loss Loss ofk-nearest neighbor classifier
resubLoss Loss ofk-nearest neighbor classifier by resubstitution
compareHoldout Compare accuracies of two classification models using new data
edge Edge ofk-nearest neighbor classifier
margin Margin ofk-nearest neighbor classifier
partialDependence Compute partial dependence
plotPartialDependence Create partial dependence plot (PDP) and individual conditional expectation (ICE) plots
resubEdge Edge ofk-nearest neighbor classifier by resubstitution
resubMargin Margin ofk-nearest neighbor classifier by resubstitution
predict Predict labels usingk-nearest neighbor classification model
resubPredict Predict resubstitution labels ofk-nearest neighbor classifier
pdist Pairwise distance between pairs of observations
pdist2 Pairwise distance between two sets of observations

Objects

expand all

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

Topics

Train Nearest Neighbor Classifiers Using Classification Learner App

Create and compare nearest neighbor classifiers, and export trained models to make predictions for new data.

Visualize Decision Surfaces of Different Classifiers

This example shows how to visualize the decision surface for different classification algorithms.

Supervised Learning Workflow and Algorithms

Understand the steps for supervised learning and the characteristics of nonparametric classification and regression functions.

Classification Using Nearest Neighbors

Categorize data points based on their distance to points in a training data set, using a variety of distance metrics.

Related Information