Understanding k-nearest neighbors