Skip to main content
. 2020 Oct 26;20(21):6075. doi: 10.3390/s20216075
Algorithm3. K-nearest neighbor (KNN) algorithm.
Input: Label data set Dl={xi,yi}i=1l
   Pseudocode labeled unlabeled data set Du={xj}j=1u
   The parameter K in the KNN algorithm
Process
1. for j = 1: u
2.   for i = 1: l
3.    Calculate the Euclidean distance Sji between {xj} and {xi}
4.   end
5.   Sort the labelled data set Dl in ascending order according to the distance Sji
6.   Select the first K data with tags, record their distance and tag information {s1,y1},,{sK,yK}
7.   for k = 1: K
8.    wk=exp(sk2/2)
9.   end
   yi=k=1KwkykkKwk
11. end
12.   Get pseudo-labelled data set Dp={xj,yj}j=1u
Outputs: Dknn=DlDp