PROCEDURE
|
K-NEAREST NEIGHBOURS
|
BEGIN
|
|
|
Split dataset into training set and validation set
|
|
|
|
Define k value
|
REPEAT
|
|
|
Calculate the distance between the query point and the training points using the Euclidean distance formula
|
|
|
|
Add the distance and the index of the training point to an ordered collection of distance subsets
|
|
|
|
Sort the ordered collection of distance subsets and indices by the distances in ascending order
|
|
|
|
Pick the top k distance subsets from the sorted collection
|
|
|
|
Get the labels of the selected k subsets
|
|
|
|
Include the mean of k labels to the prediction dataset
|
|
|
UNTIL
|
All queries in the validation dataset are calculated
|
|
|
RETURN
|
Prediction dataset
|
END
|
|