Main method for k_nearest_neighbors