[R] help with knn from class library
Liaw, Andy
andy_liaw at merck.com
Tue Aug 24 14:22:35 CEST 2004
> From: Martin Olivier
>
> Hi all,
>
> I made some computations with the knn function from the class library.
> If I execute this function several times (with the same parameters k,
> training set and test set), I obtain different results.
> I don't understand why the results for my test set are
> different. Could
> you give me some explanations?
> Is the solution for a k-nearest-neighbor classifier unique?
Could it be that you have ties in the data? There's a `use.all' argument:
use.all: controls handling of ties. If true, all distances equal to
the 'k'th largest are included. If false, a random selection
of distances equal to the 'k'th is chosen to use exactly 'k'
neighbours.
So you may want to try that. The other thing to try is to set.seed() before
calling knn().
Andy
> Best regards.
More information about the R-help
mailing list