MATLAB: How to retrieve nearest neighbor information from ClassificationKNN object

classificationknncreatensknnknnsearchStatistics and Machine Learning Toolbox

I am using the Classification Learner app to create a ClassificationKNN model. When classifying with this model, I would like to know which neighbors determined the classification (i.e. the nearest neighbors). How can I get this information?

Best Answer

There is currently no way to retrieve this information directly from the ClassificationKNN model. However, other MATLAB functions can be used to determine the nearest neighbors. You will need to create a KNN searcher using the 'createns' function.
You could also use the 'knnsearch' function.
Related Question