x <- c('e1071','caret');for(i in x){if(!require(i,character.only=T)){
  install.packages(i,dependencies=T);library(i,character.only=T)}};rm(x,i)
#--------------------------------------------------------------------
ifname<-"irisAll.csv"
#-----------------------------------------------------------
alldata<-read.csv(ifname,row.names=1,header=T,as.is=TRUE)
#[1]-Assessment of training data ---------------------------------------
results.nb<-train(Species~.,
                  data=alldata,
                  method='nb',
                  trControl=trainControl(method="LOOCV")
                  )
legenddata<-unique(alldata[,5]); legenddata
#[2]-results------------------------------------------------------------
names(results.nb$finalModel)
names(results.nb$finalModel$tables)
results.nb$finalModel$tables
#[3]-plot of probability density----------------------------------------
type4 <- names(results.nb$finalModel$tables)
for(bb in 1:4){
  tt <- type4[bb]
  sp3 <- unique(alldata$Species)
  plot(0,0,xlim=c(0,10),ylim=c(0,8),type="n",main=tt,
       xlab="feature quantity",ylab="probability density")
  for(aa in 1:3){
    ss <- sp3[aa]
    tmp <- results.nb$finalModel$tables[[bb]][[aa]]
    points(tmp$x, tmp$y, col=1, type="l",lwd=3,lty=aa)
  }
  legend("topright",legend=legenddata,pch=20,col=1,lty=1:3,cex=1.0)
}