Skip to main content
. 2017 Mar 21;17(3):649. doi: 10.3390/s17030649
Algorithm 1. KNN.
Input: Samples that need to be categorized: Xj; the known sample pairs: (Xi, yi)
Output: Prediction classification: yj
1: for every sample in the dataset to be predicted do
2:  calculate the distance between (Xi, yi) and the current sample Xj
3:  sort the distances in increasing order
4:  select the k samples with the smallest distances to Xj
5:  find the majority class of the k samples
6:  return the majority class as the prediction classification yj
7: end For