nm(x, ...)
## S3 method for class 'default':
nm(x, grouping, gamma = 0, ...)
## S3 method for class 'data.frame':
nm(x, ...)
## S3 method for class 'matrix':
nm(x, grouping, ..., subset, na.action = na.fail)
## S3 method for class 'formula':
nm(formula, data = NULL, ..., subset, na.action = na.fail)formula is not given)formula is not given)groups ~ x1 + x2 + ....
That is, the response is the grouping factor and the right hand side specifies the (non-factor) discriminatorsformula are preferentially to be takengamma=0 the posterior is 1 for the
nearest class (mean) and 0 else.NAs are
found. The default action is for the procedure to fail. An
alternative is na.omit, which leads to rejection of cases with
missing valuessknn functionlearn)).nm is calling sknn with the class means as observations.
If gamma>0 a gaussian like density is used to weight the distance to the class means
weight=exp(-gamma*distance). This is similar to an rbf kernel.
If the distances are large it may be useful to scale the data first.sknn, rda, knndata(B3)
x <- nm(PHASEN ~ ., data = B3)
x$learn
x <- nm(PHASEN ~ ., data = B3, gamma = 0.1)
predict(x)$postRun the code above in your browser using DataLab