Note: This page has been translated by MathWorks. Please click here

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

To train a * k*-nearest neighbors model, use
the Classification Learner app.
For greater flexibility, train a

`fitcknn`

in the command-line interface.
After training, predict labels or estimate posterior probabilities
by passing the model and predictor data to `predict`

.Classification Learner | Train models to classify data using supervised machine learning |

`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 |

`ClassificationKNN` |
k-nearest neighbor classification |

`ClassificationPartitionedModel` |
Cross-validated classification model |

`ExhaustiveSearcher` |
Exhaustive nearest neighbors searcher |

`KDTreeSearcher` |
Nearest neighbor search using Kd-tree |

**Train Nearest Neighbor Classifiers Using Classification Learner
App**

Learn how to train nearest neighbor classifiers.

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

`Y`

. For a positive
real value `Y`

.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 a * k*-nearest neighbor classifier.

**Characteristics of Classification Algorithms**

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

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

`Y`

. For a positive
real value `Y`

.**K-Nearest Neighbor Classification for
Supervised Learning**

The `ClassificationKNN`

classification
model lets you:

Was this topic helpful?