フィルターのクリア

How can i get KNN classifier for test and training purpose?

2 ビュー (過去 30 日間)
sam  CP
sam CP 2017 年 3 月 8 日
コメント済み: Star Strider 2017 年 3 月 8 日
I want to study about KNN classifier and i would like to implement it..Where can i get source code..

回答 (1 件)

Star Strider
Star Strider 2017 年 3 月 8 日
If you do not have the Statistics and Machine Learning Toolbox and with it the knnsearch (link) function, a simple KNN classifier is straightforward to write.
The Code
V = randi(50, 1, 3); % Vector — Create Data
M = randi(50, 15, 3); % Matrix — Create Data
dif = bsxfun(@minus, V, M); % Subtract Vector from Matrix
D2 = sqrt(sum(dif.^2,2)); % Euclidean Distance Metric
[Ds,Ix] = sort(D2,'ascend'); % Sort Ascending
k = 5; % Number Of Neighbours
KNN = M(Ix(1:k),:); % K-th Nearest Neighbours
This finds the ‘nearest neighbours’ in ‘M’ to the vector ‘V’. The data in ‘V’ and ‘M’ must have the same column size.
  2 件のコメント
sam  CP
sam CP 2017 年 3 月 8 日
Is this KNN is an inbuilt function???
Star Strider
Star Strider 2017 年 3 月 8 日
No. This is code I wrote earlier to illustrate how a k-th nearest neighbour classifier works.
The link I provided in my Answer is to the documentation for the MATLAB function. You must have the Statistics and Machine Learning Toolbox installed to use the knnsearch function.

サインインしてコメントする。

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by