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

1 回表示 (過去 30 日間)
Moritz Hesse
Moritz Hesse 2019 年 4 月 24 日
編集済み: Moritz Hesse 2019 年 4 月 24 日
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?

回答 (0 件)

カテゴリ

Help Center および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by