Skip to content
Prev 156521 / 398502 Next

How to do knn regression?

Hi Shengqiao,

I don't know any direct solutions to your question, but I don't think
it's difficult to write a few lines of code to find the k-nearest
neighbours for an observation with a missing value. Typically you need
the function dist() to compute distances, rank() or order() to find
the k-nearest neighbours, and finally using mean() or median() or any
statistic to make predictions.

To assure you the light work of programming, I can tell you all the
code of this example
(http://animation.yihui.name/dmml:k-nearest_neighbour_algorithm) is no
more than 100 lines :-D

But seriously speaking, I don't think my method is efficient. Maybe C
code will be much faster, as the knn() function in package 'class' has
called.

Regards,
Yihui
--
Yihui Xie <xieyihui at gmail.com>
Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086
Mobile: +86-15810805877
Homepage: http://www.yihui.name
School of Statistics, Room 1037, Mingde Main Building,
Renmin University of China, Beijing, 100872, China
On Fri, Sep 19, 2008 at 10:17 AM, Shengqiao Li <shli at stat.wvu.edu> wrote: