| Algorithm 1. KNN. | |
| Input: | Samples that need to be categorized: ; the known sample pairs: (, ) |
| Output: | Prediction classification: |
| 1: | for every sample in the dataset to be predicted do |
| 2: | calculate the distance between (, ) and the current sample |
| 3: | sort the distances in increasing order |
| 4: | select the k samples with the smallest distances to |
| 5: | find the majority class of the k samples |
| 6: | return the majority class as the prediction classification |
| 7: | end For |