Learn R Programming

gencve (version 0.3)

yh_kNN: kNN or NN prediction

Description

Given training data and test examples, the kNN predictions for the test data are produced. The tuning parameter k is automatically selected by specifying one of the methods: LOOCV, MLE or NN.

Usage

yh_kNN(dfTr, dfTe, method = c("LOOCV", "MLE", "NN"), k=1)

Arguments

dfTr
dataframe with last column for the output. The output must be a factor.
dfTe
dataframe for test data. Must have columns corresponding to the training columns except the test output is not needed.
method
One of the automatic methods for selecting k, the number of nearest neighbours. The default is LOOCV.
k
Pre-specified k but this value of k is only used when method="NN" otherwise when method="LOOCV" or method="MLE", k is estimated.

Value

The mis-classification rate (cost) and correlation of prediction and test.

See Also

yh_C50, yh_CART, yh_RF, yh_svm, yh_NB, yh_lda, yh_logistic, yh_qda

Examples

Run this code
yh_kNN(SinghTrain[,c(1:10, 101)], SinghTest[,c(1:10, 101)])#0.088
yh_kNN(SinghTrain[,c(1:10, 101)], SinghTest[,c(1:10, 101)], method="NN")#0.088

Run the code above in your browser using DataLab