Effacer les filtres
Effacer les filtres

K nearest neighbour predict() and knnsearch() not giving same result

1 vue (au cours des 30 derniers jours)
Moritz Hesse
Moritz Hesse le 24 Avr 2019
Modifié(e) : Moritz Hesse le 24 Avr 2019
Hi experts,
I have a ClassificationKNN object called KNNMdl which I would like to use to predict new data from my table called test_data. When I make the prediction I would also like to see the nearest neighbours used to make the prediction. However, the results of the predict and knnsearch functions yield different results
predict_row = 3176;
predicted = predict(KNNMdl, test_data{predict_row, :})
% Yields : '706'
However, when I use the knnsearch function, the highest number of closest neighbours are not from the '706' class, but from a different class:
knn_search = knnsearch(table2array(KNNMdl.X), test_data{predict_row, :},'K',20);
%knn_search returns indicies of nearest k datapoints. From this, get class labels:
nearest_classes = KNNMdl.Y(knn_search);
The nearest_classes variable shows that from the 20 closest neighbours, only 4 are in the '706' class, and the remaining 16 are in the '999' class.
What am I doing wrong? Or have I misunderstood the functionality of the knnsearch function?

Réponses (0)

Catégories

En savoir plus sur Statistics and Machine Learning Toolbox dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by