Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
Moritz Hesse
Moritz Hesse el 24 de Abr. de 2019
Editada: Moritz Hesse el 24 de Abr. de 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?

Respuestas (0)

Categorías

Más información sobre Statistics and Machine Learning Toolbox en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by