Description Usage Arguments Details Value Author(s) References See Also Examples
Uses the profile pseudolikelihood to obtain the estimate for k, the number of nearest neighbors parameter in kNN.
1 |
X |
An n-by-p matrix of covariates |
Y |
Outputs with Q classes |
kmax |
The maximum size of k |
plot |
if TRUE, plot the profile deviance otherwise no plot |
When Q=2, the glm algorithm is used to compute the profile
pseudologlikelihood and for Q>2, the function multinom
in nnet is used.
The estimate of k obtained by maximizing the pseudolikelihood is returned. It can take any value from k=0 to k=kmax.
The result is returned invisibly if plot is TRUE.
A. I. McLeod Maintainer: <aimcleod@uwo.ca>
Holmes, C. C. and Adams, N. M. (2003). Likelihood inference in nearest-neighbour classification models, Biometrika, 90(1), 99-112. http://biomet.oxfordjournals.org/cgi/content/abstract/90/1/99
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.