#Two classes example
X <- MASS::synth.tr[,1:2]
Y <- MASS::synth.tr[,3]
kNN_MLE(X=X, Y=Y, plot=FALSE)
## Not run:
# #Three classes example
# library("MASS") #need lda
# Y<- iris[,5]
# X<- iris[,1:4]
# kopt <- kNN_MLE(X, Y)
# kopt
# #Mis-classification rates on training data.
# #Of course FLDA does better in this case.
# y <- factor(Y)
# ans <- class::knn(train=X, test=X, k=kopt, cl=y)
# etaKNN <- sum(ans!=y)/length(y)
# iris.ldf <- MASS::lda(X, y)
# yfitFLDA <- MASS::predict.lda(iris.ldf, newdata=X, dimen=1)$class
# etaFLDA <- sum(yfitFLDA!=y)/length(y)
# eta<-c(etaFLDA, etaKNN)
# names(eta)<-c("FLDA", "kNN")
# eta
# ## End(Not run)
Run the code above in your browser using DataLab