implementation of KNN AM using the old coding method