[R] Interpreting knn Results

Liaw, Andy andy_liaw at merck.com
Mon Mar 29 13:19:12 CEST 2004


Maybe you should show your colleague how to access help pages in R?  Right
in ?knn, it says:

    prob: If this is true, the proportion of the votes for the winning
          class are returned as attribute 'prob'. 

so 1.0 mean all three NNs are of the `winning'; i.e., predicted, class, and
0.66667 means 2 out of the 3 NNs are of the winning class, etc.  

Andy

> From: Ko-Kang Kevin Wang
> 
> Hi,
> 
> [I'm posting this on behalf of a colleague -- as I don't know 
> knn myself...]
> 
> How to interpret the knn() results?
> 
> Tried the example codes in the documentation:
>      data(iris3)
>      train <- rbind(iris3[1:25,,1], iris3[1:25,,2], iris3[1:25,,3])
>      test <- rbind(iris3[26:50,,1], iris3[26:50,,2], iris3[26:50,,3])
>      cl <- factor(c(rep("s",25), rep("c",25), rep("v",25)))
>      knn(train, test, cl, k = 3, prob=TRUE)
>      attributes(.Last.value)
> and got:
> $levels
> [1] "c" "s" "v"
> 
> $class
> [1] "factor"
> 
> $prob
>  [1] 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000
>  [7] 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000
> [13] 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000
> [19] 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000
> [25] 1.0000000 1.0000000 1.0000000 0.6666667 1.0000000 1.0000000
> [31] 1.0000000 1.0000000 1.0000000 0.6666667 1.0000000 1.0000000
> [37] 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000
> [43] 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000
> [49] 1.0000000 1.0000000 1.0000000 0.6666667 0.7500000 1.0000000
> [55] 1.0000000 1.0000000 1.0000000 1.0000000 0.5000000 1.0000000
> [61] 1.0000000 1.0000000 1.0000000 0.6666667 1.0000000 1.0000000
> [67] 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 0.6666667
> [73] 1.0000000 1.0000000 0.6666667
> 
> 
> What do the prob mean?
> 
> Thanks,
> 
> Kevin
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> 
> 


------------------------------------------------------------------------------
Notice:  This e-mail message, together with any attachments,...{{dropped}}




More information about the R-help mailing list