matlab knn,MATLAB K近邻算法 — knnsearch() 函数 | 学步园
K近鄰
IDX = knnsearch(X,Y) finds the nearest neighbor in X for each point in
Y. X is an MX-by-N matrix and Y is an MY-by-N matrix. Rows of X and Y
correspond to observations and columns correspond to variables. IDX is
a column vector with MY rows. Each row in IDX contains the index of
the nearest neighbor in X for the corresponding row in Y.
IDX = knnsearch(X, Y) 在向量集合X中找到分別與向量集合Y中每個(gè)行向量最近的鄰居。X大小為MX-by-N矩陣,Y為大小MY-by-N的矩陣,X和Y的行對(duì)應(yīng)觀測(cè)的樣本
列對(duì)應(yīng)每個(gè)樣本的變量。IDX是一個(gè)MY維的列向量,IDX的每一行對(duì)應(yīng)著Y每一個(gè)觀測(cè)在X中最近鄰的索引值。
[IDX, D] = knnsearch(X,Y) returns a MY-by-1 vector D containing the
distances between each row of Y and its closest point in X.
[IDX, D]= knnsearch(X,Y,'NAME1',VALUE1,...,'NAMEN',VALUEN) specifies
optional argument name/value pairs:
Name ? ? ? ? ?Value
'K' ? ? ? ? ? A positive integer, K, specifying the number of nearest
neighbors in X to find for each point in Y. Default is
1. IDX and D are MY-by-K matrices. D sorts the
distances in each row in ascending order. Each row in
IDX contains the indices of K closest neighbors in X
corresponding to the K smallest distances in D.
“K”表示最近鄰個(gè)數(shù),返回值D是按行升序排列。
'NSMethod' ? ?Nearest neighbors search method. Value is either:
搜尋的方法參數(shù)
'Distance' ? ? A string or a function handle specifying the distance
選擇何種距離作為最近鄰的度量標(biāo)準(zhǔn)
Example:
% Find 2 nearest neighbors in X and the corresponding values to each
% point in Y using the distance metric 'cityblock'
X = randn(100,5);
Y = randn(25, 5);
[idx, dist] = knnsearch(X,Y,'dist','cityblock','k',2);
總結(jié)
以上是生活随笔為你收集整理的matlab knn,MATLAB K近邻算法 — knnsearch() 函数 | 学步园的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 计算机考研没奖,备战考研本科期间没有什么
- 下一篇: java 多线程统计质数,Java 七