# Varying the number of neighbors in nearest-neighbors regression

For nearest-neighbors regression, it is plausible to increase the number of neighbors used to predict $$f(x)$$ when there are many data points near $$x$$.

What is a good algorithm for varying the number of neighbors used?