필터 지우기
필터 지우기

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 CenterFile Exchange에서 Statistics 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