Stata implements the k nearest neighbor algorithm in discrim knn. I would like to identify which observation(s) are the nearest neighbors. Below is an example
with k=3. The prediction works fine. I want to identify which 3 neighbors are used each time. Any thoughts?
version 15
clear
set obs 400
gen y=uniform()
replace y= round(y)
gen x1=uniform()
gen x2=uniform()
discrim knn x1 x2 , k(3) group(y)
predict myclass, classification
with k=3. The prediction works fine. I want to identify which 3 neighbors are used each time. Any thoughts?
version 15
clear
set obs 400
gen y=uniform()
replace y= round(y)
gen x1=uniform()
gen x2=uniform()
discrim knn x1 x2 , k(3) group(y)
predict myclass, classification
Comment