implement a KNN (K-Nearest Neighbors) model for classification in MATLAB

hello ,I'm trying to implement a KNN (K-Nearest Neighbors) model for classification in MATLAB (Similar Image Finder project). do you know how to determine the optimal number of neighbors (k) for the datase
Solution:
Conventionally, the value of k is taken as sqrt(N) where N is the number of data points in your dataset. But a better approach is to take a random sample (5% of your main dataset) and use the trial and error method to find the optimal k value that works best for that particular sample. Statistically, the optimal k value you find out in that sample should also be the optimal k value for your entire dataset....
Jump to solution
1 Reply
Solution
saumitrajagdale
saumitrajagdale9mo ago
Conventionally, the value of k is taken as sqrt(N) where N is the number of data points in your dataset. But a better approach is to take a random sample (5% of your main dataset) and use the trial and error method to find the optimal k value that works best for that particular sample. Statistically, the optimal k value you find out in that sample should also be the optimal k value for your entire dataset.
Want results from more Discord servers?
Add your server