[R] Interpreting knn Results

Ko-Kang Kevin Wang k.wang at auckland.ac.nz
Mon Mar 29 06:46:34 CEST 2004


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




More information about the R-help mailing list