# Python kNN vs. radius nearest neighbor regression

Python offers two nearest neighbor regressions: radius nearest neighbor and k-nearest neighbor. I'm trying to figure out a few things: 1. Under which circumstances would each be preferable? 2. How do you approach setting the optimal radius or k value?

For reference, I'm working with a relatively sparse data set with a uniform geometry. As time passes, that dataset will get less sparse, but will continue to have a relatively uniform geometry.

Thanks for any help.

• This answer to (2) is incorrect and will lead to overfitting. If you optimize $k$ or the radius on the training set, the optimal choice of $k$ will be 1, and the optimal radius will be zero (or any value smaller than the minimum distance to the next-nearest neighbor). This is because each point in the training set is its own nearest neighbor, and outputting its corresponding target value will give zero error on the training set. This will probably not generalize well to new data. The proper procedure is to select $k$ or the radius using cross validation or an independent validation set. – user20160 Nov 11 '18 at 6:25