Description Usage Arguments Details Value Examples
k Nearest Neighbors with Grid Search Variable Selection
1 2 3 4 5 6 7 8 |
train_x |
matrix or data frame of training set |
test_x |
matrix or data frame of test set |
cl_train |
factor of true classifications of training set |
cl_test |
factor of true classifications of test set |
k |
the number of neighbors |
model |
regression or classifiation |
kNNvs is simply use add one and then compare acc to pick the best variable set for the knn model
ACC or MSE, best variable combination, estimate value yhat
1 2 3 4 5 6 7 8 9 10 11 12 13 | {
data(iris3)
train_x <- rbind(iris3[1:25,,1], iris3[1:25,,2], iris3[1:25,,3])
test_x <- rbind(iris3[26:50,,1], iris3[26:50,,2], iris3[26:50,,3])
cl_train<- cl_test<- factor(c(rep("s",25), rep("c",25), rep("v",25)))
k<- 5
# cl_test is not null
mymodel<-kNNvs(train_x,test_x,cl_train,cl_test,k,model="classifiation")
mymodel
# cl_test is null
mymodel<-kNNvs(train_x,test_x,cl_train,cl_test=NULL,k,model="classifiation")
mymodel
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.