k-Nearest Neighbors (kNN) Classifier

版本 2.2.1 (35.8 KB) 作者: David Ferreira
Multi-class Classification with the kNN
2.1K 次下载
更新时间 2020/10/28

Function
1. kNNeighbors.predict(_)
2. kNNeighbors.find(_)

Description
1. Returns the estimated labels of one or multiple test instances.
2. Returns the indices and the respective distances of the k nearest training instances.

Examples using Iris Data Set

load fisheriris

X = meas;
Y = species;
Xnew = [min(X);mean(X);max(X)];
k = 5;
metric = 'euclidean';

mdl = kNNeighbors(k,metric);
mdl = mdl.fit(X,Y);
Ypred = mdl.predict(Xnew)

Ypred =

'setosa'
'versicolor'
'virginica'


Ynew = {'versicolor';'versicolor';'virginica'};
accuracy = accuracy_score(Ypred,Ynew)

accuracy =

0.6667

See examples in the script files.

引用格式

David Ferreira (2019). k-Nearest Neighbors (kNN) (https://www.mathworks.com/matlabcentral/fileexchange/67018-k-nearest-neighbors-knn), MathWorks. Retrieved January 23, 2019.

MATLAB 版本兼容性
创建方式 R2016a
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Statistics and Machine Learning Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

无法下载基于 GitHub 默认分支的版本

版本 已发布 发行说明
2.2.1

See release notes for this release on GitHub: https://github.com/ferreirad08/kNNeighborsClassifier/releases/tag/2.2.1

2.2.0

See release notes for this release on GitHub: https://github.com/ferreirad08/k-Nearest-Neighbors-kNN-Algorithm/releases/tag/2.2.0

2.1.9

See release notes for this release on GitHub: https://github.com/ferreirad08/k-Nearest-Neighbors-kNN-Algorithm/releases/tag/2.1.9

2.1.8

Find function added

2.1.7

Description correction

2.1.6

Description correction

2.1.5

Description correction

2.1.4

Description correction

2.1.3

3-D chart added and cell type label support.

2.1.2

The plotting 3-D function was added in the main algorithm.

2.1.1

More markers were added to the chart.

2.1.0

The plotting function was added in the main algorithm.

2.0.9

Function Pack

2.0.8

Title correction

2.0.7

Title correction

2.0.6

Added to github.

2.0.5

New tools have been added, bringing a more complete algorithm.

2.0.4

Simplification in k nearest instances and k nearest labels

2.0.3

Basic update

2.0.2

Update in maximum frequency

2.0.1

Simplification in frequency verification

2.0.0

Check the frequencies using 'histcounts'

1.62

Title correction

1.61

Correction of the k nearest labels.

1.60

Returns the k nearest labels.

1.54

Basic update

1.53

Updating the Euclidean distance between two points

1.52

Description correction

1.51

Description correction

1.5

Elements sorted by "sort" function and reduced processing time by approximately 1/3.

1.1.0.0

Update of the calculation of the Euclidean distance between two points

1.0.0.0

Description correction
It was added the verification of the dimensions of the matrices.

要查看或报告此来自 GitHub 的附加功能中的问题,请访问其 GitHub 仓库
要查看或报告此来自 GitHub 的附加功能中的问题,请访问其 GitHub 仓库