knnAlgorithm base code