implementing k-nearest sample size