Applying the k-nearest neighbor algorithm