The knn search part is wrong. The k bin vector repeat the same element k times.
This time kNN classifier seems correct.