function [yhat] = k_nn(k,Y,X,w); % k-nearest neighbor routine % calculates k-nearest neighbor estimate of E[y|x] at each point % given in the vector w. % % if there are multiple neighbors at the same distance, picks k % of them at random % % k: a positive integer, k