KNN code