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.
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Create scripts with code, output, and formatted text in a single executable document.
best